Skip to main content
gamedev.net
🔒 Locked

[web] PHP strtotime format problem

Started by gavco98 0 replies 750+ views
Original Post
gavco98
gavco98
I am trying to use strtotime() to convert a date into a timestamp for storage in a db. However the dates are in UK format, ie /DD/MM/YYYY, yet the function is treating them as US format MM/DD/YYYY and giving the wrong timestamp. How can I force the strtotime() to expect UK format dates?
Gavin Coates
[size="1"]IT Engineer / Web Developer / Aviation Consultant
[size="1"][ Taxiway Alpha ] [ Personal Home Page ]
konForce
konForce
I don't believe there is any way to do that. However, you could do something like:
// explodelist($d,$m,$y) = explode('/',$date);$ts = mktime(0,0,0,$m,$d,$y);// regular expression versionif (preg_match('!([0-9]{1,2})/([0-9]{1,2})/([0-9]{2,4})!', $date, $matches)){  list(,$d,$m,$y) = $matches;  $ts = mktime(0,0,0,$m,$d,$y);}else  $ts = NULL;

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.