Home > Database > Mysql Tutorial > body text

Why am I Getting the Wrong Year When Displaying a Date in ISO 8601 Format with PHP?

Susan Sarandon
Release: 2024-11-09 06:20:02
Original
306 people have browsed it

Why am I Getting the Wrong Year When Displaying a Date in ISO 8601 Format with PHP?

How to Display a Date as ISO 8601 Format with PHP Correctly

You're facing an issue where the date format is incorrect when attempting to display a datetime from a MySQL database using the date function. Instead of the expected year of 2008, you're getting the incorrect year of 1969.

The root cause of this issue lies in the second argument of the date function. You're mistakenly supplying a MySQL database timestamp string instead of a UNIX timestamp.

To resolve this error, you need to convert your database timestamp to a UNIX timestamp using the strtotime function. Here's the corrected code:

<?php echo date("c", strtotime($post[3])); ?>
Copy after login

By utilizing strtotime, you accurately convert your database timestamp into a UNIX timestamp, ensuring that the date function displays the correct ISO 8601 formatted string.

The above is the detailed content of Why am I Getting the Wrong Year When Displaying a Date in ISO 8601 Format with PHP?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template