sMyles
sMyles

Reputation: 2706

PHP time() changes hours and seconds but not minutes?

I'm trying to output the current date and time using this code:

$theDate = date('y-m-d H:m:s', time());
echo $theDate; 

And it works fine but the output for time does not change minutes, it simply sites at HH:07:SS, so the minute sits at 07 and the only thing that changes is the seconds and hours.

Is this because of the time function inside PHP? Does it only update minutes so often? Why would it not update the minutes as well?

How can I get an output the same but with minutes showing correctly?

Whenever i run strftime on the server it outputs fine, just trying to figure it out above.

Upvotes: 2

Views: 1419

Answers (4)

Kevin Ji
Kevin Ji

Reputation: 10499

m represents months, not minutes. You need to use i for minutes. See the date() manual page for more information.

$theDate = date('y-m-d H:i:s'); echo $theDate;

Upvotes: 2

SeanCannon
SeanCannon

Reputation: 78046

Use i not m:

$theDate = date('y-m-d H:i:s'); echo $theDate;

07 is July :)

Upvotes: 8

SBSTP
SBSTP

Reputation: 3639

You dont need to give date function the second parameter time().

Just try date("format string");

Upvotes: 0

Francesco Laurita
Francesco Laurita

Reputation: 23552

Your format string is wrong.

It could be: y-m-d H:i:s

Upvotes: 1

Related Questions