On passing an out-of-range value in UNIX_TIMESTAMP() or FROM_UNIXTIME() function, what MySQL will return?

MySQLMySQLi Database

When we pass an out-of-range value in UNIX_TIMESTAMP, MySQL returns 0. The valid range of value is same as for the TIMESTAMP data type.

Example

mysql> Select UNIX_TIMESTAMP('1969-01-01 04:05:45');
+---------------------------------------+
| UNIX_TIMESTAMP('1969-01-01 04:05:45') |
+---------------------------------------+
|                         0             |
+---------------------------------------+
1 row in set (0.00 sec)

When we pass an out-of-range value in FROM_UNIXTIME, MySQL returns NULL. The valid range of values is same as for the INTEGER data type.

Example

mysql> Select FROM_UNIXTIME(2147483648);
+---------------------------+
| FROM_UNIXTIME(2147483648) |
+---------------------------+
| NULL                      |
+---------------------------+
1 row in set (0.00 sec)
raja
Published on 19-Feb-2018 11:28:36
Advertisements