Home > Database > Mysql Tutorial > body text

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

PHPz
Release: 2023-08-25 09:57:02
forward
1005 people have browsed it

为什么我在将“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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!