Re: Date Conversion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>"Ng Hwee Hwee" <hhwee@xxxxxxxxxxx> wrote in message
news:009801c484f1$d11c8af0$800101df@xxxxxxxxxxx
>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

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux