user3656119
user3656119

Reputation: 41

PHP - strftime (minutes and seconds ignored)?

I tried to save time in format YYYY-mm-dd 23:59:59 to mysql database column with datetime. I don't understand why minutes and seconds are ignored always 00 ? Thank you very much for help.

PHP:

$time = strftime('%Y-%m-%d %H:%i:%s', time());

Output:

2014-07-16 11:00:00

Upvotes: 0

Views: 703

Answers (4)

plr
plr

Reputation: 511

you have to specify timezone as follows.

date_default_timezone_set('Australia/Melbourne'); $date = date('m/d/Y h:i:s a', time()); echo $date;

The time would go by your server time. An easy workaround for this is to manually set the timezone by using date_default_timezone_set before the date() or time() functions.

Upvotes: 1

cornelb
cornelb

Reputation: 6066

You are looking for

$time = strftime('%Y-%m-%d %H:%M:%S', time());

from the documentation

%S Two digit representation of the second %M Two digit representation of the minute 00 through 59

Also, what PHP version are you using? %i:%s should not be 00:00

Upvotes: 0

Hossam Aldeen Ahmed
Hossam Aldeen Ahmed

Reputation: 782

you can use mysql function

now()

Upvotes: 0

Marcin Nabiałek
Marcin Nabiałek

Reputation: 111859

You can simple use:

$time = date("Y-m-d H:i:s");

or even better use mysql NOW() function

Upvotes: 2

Related Questions