Jump to content

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


Recommended Posts

Don't store your dates as unix timestamps - store them as type DATETIME, format "yyyy-mm-dd hh:ii:ss"

Since we still don't have images on mobile view I will have to "like" this via a quote. *liked*
Link to comment
Share on other sites

$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.

Edited by gamefreak13
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.