[thelist] parsing numbers trap
Jay Greenspan
jay at trans-city.com
Fri Jun 15 11:18:21 CDT 2001
I'll just mention that MySQL's date_format() offers another way of dealing
with dates like this:
mysql> select date_format('2001-08-04', '%W %M %D, %Y');
+--------------------------------------------+
| date_format('2001-08-04', '%W %M %D, %Y') |
+--------------------------------------------+
| Saturday August 4th, 2001 |
+--------------------------------------------+
1 row in set (0.00 sec)
There are specifiers for about any format you'd need. Check the manual.
-j
on 6/15/01 12:01 PM, Winfried Huslik at winfried at huslik.de wrote:
> Hi,
>
> <tip type="mySQL, PHP">
> just reading about Netscape's blooper, here is something to be wary about:
>
> Given a Date field from mySQL like "2001-08-04" for August 4th 2001,
> I used the
>
> function longDate($d) {
> eval(ereg_replace('(#+)-(#+)-(#+)',
> '$d = mktime(0,0,0,\\2,\\3,\\1);', $d));
> return date ("l jS F Y", $d);
> }
>
> to print something like "Saturday 4th August 2001",
> but this does NOT work correct for Months or Days 08 and 09! Why?
>
> Numbers starting with zero are interpreted by PHP as octal (which go from
> 00 to 07). 08 and 09 are illegal octal numbers and taken for zero
> which shows totally confused dates.
>
> The second line must read:
> eval(ereg_replace('(#+)-0?(#+)-0?(#+)',
> to eliminate the leading zeroes.
>
> </tip>
>
More information about the thelist
mailing list