Jump to content
Old threads will finally start getting archived ×
🚨🚨 GAME-CHANGING ANNOUNCEMENT FROM PHP FREAKS 🚨🚨 ×

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
  On 6/9/2013 at 12:58 AM, Barand said:

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*
  On 6/8/2013 at 9:23 AM, gamefreak13 said:

I know I can use strtotime(), but I would feel safer specifying the format.

Why would you feel safer? strtotime() has a finite list of formats that it will accept, yours is one of them.

  On 6/9/2013 at 12:37 AM, Barand said:
$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
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.

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