select FROM_UNIXTIME(32154654321);
Output:Null
Expected Result: Tuesday, December 9, 2988 1:55:21 PM GMT+05:30
select FROM_UNIXTIME(32154654321);
Output:Null
Expected Result: Tuesday, December 9, 2988 1:55:21 PM GMT+05:30
This is the Year-2038 problem. The maximum value of the TIMESTAMP
datatype is 2038-01-19 03:14:07
, so you can't get the expected result.
MySQL 5.5: The
TIMESTAMP
data type is used for values that contain both date and time parts.TIMESTAMP
has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC. source: https://dev.mysql.com/doc/refman/5.5/en/datetime.htmlMySQL 5.6+: [...] and the range for
TIMESTAMP
values is '1970-01-01 00:00:01.000000' to '2038-01-19 03:14:07.999999'.
source: https://dev.mysql.com/doc/refman/5.7/en/datetime.html
You can find a very good answer on stackoverflow with some more details about this problem.
You can use PHP instead of MySQL to convert the timestamp (not stored in a TIMESTAMP
column) to a readable datetime, with the following code:
$timestamp = 32154654321;
$format = 'Y-m-d H:i:s';
$date = new DateTime();
$date->setTimestamp($timestamp);
echo $date->format($format);
demo: http://ideone.com/DsYUOQ
This is why: https://dev.mysql.com/doc/refman/5.5/en/datetime.html
The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.
You cannot input like 32154654321
Timestamps in mysql have a maximum value of 2147483647, equivalent to 2038-01-19 05:14:07. This is due to the underlying 32-bit limitation. Using the function on a timestamp beyond this will result in NULL being returned. Use DATETIME as a storage type if you require dates beyond this.