PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > british date format
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
british date format

Réponse
 
LinkBack Outils de la discussion
Vieux 09/05/2008, 10h58   #1
Merca, Ansta Ltd
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut british date format

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)
  Réponse avec citation
Vieux 09/05/2008, 15h22   #2
André Medeiros
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] british date format

Try this:

http://pt.php.net/manual/en/function.strptime.php

Use the result with mktime to get the timestamp. I also checked
set_locale but that won't interfere with strtotime

On Fri, May 9, 2008 at 9:58 AM, Merca, Ansta Ltd <merca@ansta.co.uk> 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)
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

  Réponse avec citation
Vieux 09/05/2008, 15h36   #3
Shawn McKenzie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: british date format

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
  Réponse avec citation
Vieux 09/05/2008, 15h40   #4
André Medeiros
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Re: british date format

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 <nospam@mckenzies.net> 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
>
>

  Réponse avec citation
Vieux 09/05/2008, 16h54   #5
Shawn McKenzie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Re: british date format

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 <nospam@mckenzies.net>
>> 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

  Réponse avec citation
Vieux 09/05/2008, 17h05   #6
André Medeiros
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Re: british date format

Yeah, that would be the way to do it

On Fri, May 9, 2008 at 3:54 PM, Shawn McKenzie <nospam@mckenzies.net> 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 <nospam@mckenzies.net>
>>> 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
>
>

  Réponse avec citation
Vieux 09/05/2008, 18h50   #7
Shawn McKenzie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Re: british date format

André Medeiros wrote:
> Yeah, that would be the way to do it
>
> On Fri, May 9, 2008 at 3:54 PM, Shawn McKenzie <nospam@mckenzies.net> 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 <nospam@mckenzies.net>
>>>> 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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 16h04.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15197 seconds with 15 queries