Forum Moderators: coopster

Message Too Old, No Replies

Use strtotime() to convert UK format dates?

ie. date string is of the form 'day/month/year'

         

penders

11:33 am on Dec 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



PHP's strtotime() function converts dates in US English format (ie. 'month/day/year') into a unix timestamp (certainly by default anyway). Is there any kind of 'locale' setting to convert UK date format strings instead? ie. 'day/month/year' ...without having to explode the string and construct the date 'manually'?

ALKateb

5:16 pm on Dec 20, 2009 (gmt 0)

10+ Year Member



echo strftime("%d/%m/%Y",strtotime("11/18/1986"));

here as u see 11/18/1986 is the date in US format by using strtotime we convert it to unix timestamp then we format the timestamp to be (d/m/Y)

penders

8:49 pm on Dec 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks for your response, it got me thinking, but it's not really what I'm after in this case.

The user passes a date string in UK date format, ie. '18/11/1986'. This then needs to be converted into a unix timestamp. I was wondering if there was any way that PHP could be configured to see a date string as being in 'd/m/Y' order by default (or any other particular format for that matter)?

I guess not (so far), so I've resorted to doing something like what is mentioned in the Bag-O-Tricks for PHP III [webmasterworld.com] thread:

$ukdate = '18/11/1986; 
list($day, $month, $year) = explode('/', $ukdate);
$usdate = $month.'/'.$day.'/'.$year;
$unixdate = strtotime($usdate);