Re: Date Conversion
| From: | Torsten Roehr | Date: | Wed, 18 Aug 2004 08:16:59 +0000 |
| Subject: | Re: Date Conversion | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-35768@lists.php.net to get a copy of this message | ||
>"Ng Hwee Hwee" <hhwee@towa.com.sg> wrote in message
news:009801c484f1$d11c8af0$800101df@hweehwee...
>Hi all,
>
>can someone kindly point me to a resource that converts all kinds of
possible date inputs into MySQL format of YYYY-MM-DD?
>
>example of formats to be converted includes:
>
>d/m/yy
>d/m/yyyy
>d/mm/yy
>d/mm/yyy
>dd/mm/yy
>dd/mm/yyy
>d/mmm/yy
>d/mmm/yyyy
>dd/mmm/yy
>dd/mmm/yyyy
>
>yy - 2 digit representation of year
>yyyy - ful numeric representation of year
>m - numeric representation of month, without leading zero
>mm - numeric representation of month, with leading zero
>mmm - short textual representation of month
>d - day of month without leading zero
>dd - day of month with leadin zero
>
>thanx!
>
>hwee
This question belongs more to the general list, but anyway:
You can use strtotime() to convert various formats to a timestamp. Then use
date() to convert it back to your preferred date format:
$timestamp = strtotime($inputDate);
$isoDate = date('Y-m-d', $timestamp);
http://de2.php.net/strtotime
http://de2.php.net/manual/en/function.date.php
Regards, Torsten Roehr