Interval datatype in MySql

前端 未结 2 1139
忘掉有多难
忘掉有多难 2021-01-12 23:06

Does MySql has the Interval datatype as PostgreSQL (or like TimeSpan in .net) does?

相关标签:
2条回答
  • 2021-01-12 23:26

    No. There are interval functions, but not datatypes.

    If the intervals you're concerned with are less than 838 hours, you might be able to use the TIME type to get the behavior you want.

    From the manual:

    MySQL interprets TIME values as elapsed time rather than as time of day.
    
    0 讨论(0)
  • 2021-01-12 23:33

    Nope, there is no time interval data type in MySQL. There is a feature request for one though, but apparently it hasn't gotten much attention.

    The time type can be used for such a purpose though, as suggested by the documentation

    MySQL retrieves and displays TIME values in 'HH:MM:SS' format (or 'HHH:MM:SS' format for large hours values). TIME values may range from '-838:59:59' to '838:59:59'. The hours part may be so large because the TIME type can be used not only to represent a time of day (which must be less than 24 hours), but also elapsed time or a time interval between two events (which may be much greater than 24 hours, or even negative).

    0 讨论(0)
提交回复
热议问题