PHP: date/time functions give wrong minutes

Linux howto's, compile information, information on whatever we learned on working with linux, MACOs and - of course - Products of the big evil....
Post Reply
User avatar
^rooker
Site Admin
Posts: 1482
Joined: Fri Aug 29, 2003 8:39 pm

PHP: date/time functions give wrong minutes

Post by ^rooker »

[PROBLEM]:

PHP functions seem to show the wrong number of minutes in a formatted timestamp:

Commandline shell "date" program says:

Code: Select all

$ date:
Wed 18 Oct 2023 10:22:42 AM CEST
# PHP functions

Code: Select all

`printf("Time: %s\n", time());`
Time: 1697617364

`printf("Formatted: %s\n", date('Y-m-d H:m:s'));`
Formatted: 2023-10-18 10:10:44

[SOLUTION]

A common format placeholder mixup.
Quote from Mark Baker (at Stackoverflow):
If you're using "M" or "m" for minutes, then you're actually displaying month of year. "i" is used for minutes.
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
Post Reply