Re: [PHP] Re: british date format

[email protected] (Shawn McKenzie)
Newsgroups php.general
Message-ID <[email protected]>
André Medeiros wrote:
> Yeah, that would be the way to do it ;)
> 
> On Fri, May 9, 2008 at 3:54 PM, Shawn McKenzie <[email protected]> wrote:
>> Shawn McKenzie wrote:
>>> André Medeiros wrote:
>>>> Shawn,
>>>>
>>>> I think the idea here was to get a timestamp from a date in that
>>>> format he was telling about.
>>>>
>>>> After replying however, I noticed that strptime is only implemented in
>>>> PHP5. Sorry about that mate.
>>>>
>>>> On Fri, May 9, 2008 at 2:36 PM, Shawn McKenzie <[email protected]>
>>>> wrote:
>>>>> Merca, Ansta Ltd wrote:
>>>>>> Hi
>>>>>>
>>>>>> Anyone "dd/mm/yyyy" as a date variable? strtotime - works fine with
>>>>>> "mm/dd/yyyy" but now with "dd/mm/yyyy". (PHP 4.x)
>>>>> setlocale()
>>>>>
>>>>> and then...
>>>>>
>>>>> http://pt.php.net/manual/en/function.strftime.php
>>>>>
>>>>> -Shawn
>>>>>
>>>>> --
>>>>> PHP General Mailing List (http://www.php.net/)
>>>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>>>
>>>>>
>>> Couldn't see any other way.  *nix strtotime is supposed to use locale.
>>>
>> Fixed that for me:
>>
>> $date = '20/12/1971';
>> $d = explode('/', $date);
>> echo mktime(0 ,0, 0, $d[1], $d[0],$d[2])."\n";
>>
>>> -Shawn
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>

I was bored.  Just an example, and I named it _eur because I assume that 
all European dates are this way, but some may have a / or a - or . 
separator.  intval() is to remove preceding 0 or it is treated as octal.

<?php

function strtotime_eur($date)
{
     preg_match('|([0-9]{1,2})[/.-]([0-9]{1,2})[/.-]([0-9]{2,4})|',
		$date, $parts);

     if(count($parts) != 4) {
         return false;
     }
     $d = intval($parts[1]);
     $m = intval($parts[2]);
     $y = intval($parts[3]);

     return mktime(0 ,0, 0, $m, $d, $y);
}

?>

-Shawn
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.