SelectUNIX_TIMESTAMP('1965-05-15'"/> SelectUNIX_TIMESTAMP('1965-05-15'">

Home >Database >Mysql Tutorial >Why do I get an output of 0 (zero) when converting a date like '1965-05-15' to a TIMESTAMP?

Why do I get an output of 0 (zero) when converting a date like '1965-05-15' to a TIMESTAMP?

PHPz
PHPzforward
2023-08-25 09:57:021057browse

为什么我在将“1965-05-15”等日期转换为 TIMESTAMP 时得到输出 0(零)?

As we all know that with the help of MySQL UNIX_TIMESTAMP function we can generate the seconds of a given date/datetime. But when we try to convert a date like "1965-05-15", it gives 0 (zero) as output because the range of TIMESTAMP is from "1970-01-01 00:00:01" to "2038 -01-"between 19 08:44:07'. Therefore, date values ​​outside the TIMESTAMP range cannot be converted, and 0 is always returned as output.

Examples are as follows -

mysql> Select UNIX_TIMESTAMP ('1965-05-15');
+----------------------------------------------+
| unix_timestamp('1965-05-15 05:04:30')        |
+----------------------------------------------+
|                                       0      |
+----------------------------------------------+
1 row in set (0.00 sec)

mysql> select UNIX_TIMESTAMP ('1970-05-15 05:04:30');
+----------------------------------------------+
| unix_timestamp('1970-05-15 05:04:30')        |
+----------------------------------------------+
|                                     11576070 |
+----------------------------------------------+
1 row in set (0.00 sec)

The above is the detailed content of Why do I get an output of 0 (zero) when converting a date like '1965-05-15' to a TIMESTAMP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete