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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
> 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. |
|
|||
|
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 |
|
|||
|
..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 |
|
|||
|
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 |
![]() |
| Thread Tools | |
| Display Modes | |
|
|