PHP4 date parsing

This is a discussion on PHP4 date parsing within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi everyone How do I parse a date with PHP version 4. The problem is that the date-format is ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-25-2007
Preben
 
Posts: n/a
Default PHP4 date parsing

Hi everyone


How do I parse a date with PHP version 4.

The problem is that the date-format is like:

d-m-Y ( 15-08-2006 )


but strtotime won't accept this even though the setlocale function has
been used:
setlocale( LC_ALL, "da_DK", "da", "dan", "danish", "da_DK.ISO8859-1" );


Thanks for helping!

/ Preben
Reply With Quote
  #2 (permalink)  
Old 02-25-2007
Preben
 
Posts: n/a
Default Re: PHP4 date parsing

> How do I parse a date with PHP version 4.
>
> The problem is that the date-format is like:
>
> d-m-Y ( 15-08-2006 )
>
>
> but strtotime won't accept this even though the setlocale function has
> been used:
> setlocale( LC_ALL, "da_DK", "da", "dan", "danish", "da_DK.ISO8859-1" );


I tried to list all the locales on the server - and there are none.. So
that's probably why.

So now I just used the split-function to parse the date manually.
Reply With Quote
  #3 (permalink)  
Old 02-26-2007
Rik
 
Posts: n/a
Default Re: PHP4 date parsing

On Sun, 25 Feb 2007 20:42:56 +0100, Preben <64bitNONOSPAMno@mailme.dk>
wrote:

>> How do I parse a date with PHP version 4.
>> The problem is that the date-format is like:
>> d-m-Y ( 15-08-2006 )
>> but strtotime won't accept this even though the setlocale function
>> has been used:
>> setlocale( LC_ALL, "da_DK", "da", "dan", "danish", "da_DK.ISO8859-1" );

>
> I tried to list all the locales on the server - and there are none.. So
> that's probably why.
>
> So now I just used the split-function to parse the date manually.


Thank you for this wonderfull example against using strtotime(). Never
liked the unpredictability of this function :-)
--
Rik Wasmus
Reply With Quote
  #4 (permalink)  
Old 02-26-2007
Michael Fesser
 
Posts: n/a
Default Re: PHP4 date parsing

..oO(Rik)

>Thank you for this wonderfull example against using strtotime(). Never
>liked the unpredictability of this function :-)


It's all documented:

| The function expects to be given a string containing a US English date
| format [...]

http://www.php.net/manual/en/function.strtotime.php

| For numeric months, the ISO 8601 format `year-month-day' is allowed
| [...] The construct `month/day/year', popular in the United States, is
| accepted. Also `month/day', omitting the year.

http://www.gnu.org/software/tar/manu...11.html#SEC111

There's no word about locales, so you can't expect strtotime() to
recognize every localized date format.

In my projects I use my own date parser class, which uses some regular
expressions to recognize the most common formats (especially the German
dd.mm.yy[yy], which is what I usually need). If the matching fails, I
call strtotime() just as a fallback.

Micha
Reply With Quote
  #5 (permalink)  
Old 02-26-2007
Preben
 
Posts: n/a
Default Re: PHP4 date parsing

Michael Fesser skrev:
> .oO(Rik)
>
>> Thank you for this wonderfull example against using strtotime(). Never
>> liked the unpredictability of this function :-)

>
> It's all documented:
>
> | The function expects to be given a string containing a US English date
> | format [...]
>
> http://www.php.net/manual/en/function.strtotime.php


Well, the documentation for setlocale states that it contains date
formatting settings - but looking closer it seems it's only for strftime
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:02 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0