Jump to content

"6/8/2013 1:02:37 AM" converted to unix timestamp


gamefreak13

Recommended Posts

or

$d = '6/8/2013 1:01:27 PM';

list($m, $d, $y, $h, $i, $s, $a) = sscanf($d, '%d/%d/%d %d:%d:%d %s');

echo sprintf('%4d-%02d-%02d %02d:%02d:%02d', $y, $m, $d, $a=='AM'?$h:$h+12, $i, $s);  //--> 2013-06-08 13:01:27
$d = '6/8/2013 1:01:27 PM';

list($m, $d, $y, $h, $i, $s, $a) = sscanf($d, '%d/%d/%d %d:%d:%d %s');

echo sprintf('%4d-%02d-%02d %02d:%02d:%02d', $y, $m, $d, $a=='AM'?$h:$h+12, $i, $s);  //--> 2013-06-08 13:01:27

 

 

I tried this and it seems to work fine, thank you.

 

Need I worry about varying lengths breaking this? If I'm understanding your code correctly, it searches for forward slashes and semi-colons to seperate the year, month, day, etc. I'll do some testing (like throwing 06/08/2013 at it instead of 6/8/2013), but thought I'd ask too.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.