NZ Mikey NZ Mikey - 2 years ago 64
SQL Question

PHP strptime() Doesn't seem to work? I can't see anything wrong

I am currently trying to get a database transfered from an old system to a new one, and i have run into a small issue.

I have a db row formatted at:

2007-04-24 00:23:59
(yyyy-mm-dd hh:mm:ss)

And i cant seem to get it to work through strptime()

Here is what i have:

$format = '%Y-%m-%d %H:%i:%s';
$ct = strptime($row['time'], $format );
//$row['time'] == 2007-01-11 00:47:27

This returns nothing.

Can anyone see anything wrong with that?


Answer Source

Format should be a bit different:

$format = '%Y-%m-%d %H:%M:%S'; // or just '%F %T'

Here's the corresponding section of strftime format documentation:

%M  Two digit representation of the minute  [00 through 59]
%S  Two digit representation of the second  [00 through 59]
%T  Same as "%H:%M:%S"
%F  Same as "%Y-%m-%d" (commonly used in database datestamps)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download