Page 1 of 1

PHP: date/time functions give wrong minutes

Posted: Wed Oct 18, 2023 10:25 am
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.