Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interval datatype in MySql

Tags:

types

mysql

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

like image 385
MatteoSp Avatar asked Oct 27 '10 21:10

MatteoSp


2 Answers

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).

like image 169
Eric Petroelje Avatar answered Sep 24 '22 18:09

Eric Petroelje


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.
like image 42
kijin Avatar answered Sep 21 '22 18:09

kijin