[thelist] Converting date format with PHP

Jeremy Ashcraft ashcraft at 13monkeys.com
Thu Sep 20 23:57:43 CDT 2001


Try this on for size:

function format_date($datetime) {
 
    #match day/month/year hour:minute:seconds
    preg_match("/(\d+)\/(\d+)\/(\d+)/",$datetime,$match);

    #reformat date string
    $date = "$match[3]/$match[2]/$match[1]";
 
    return $date;
}

HTH

jeremy

On Thursday 20 September 2001 23:23, you wrote:
> Howdy y'all
>
> Well, going straight to the point:  I have a date that is typed by the user
> in the format dd/mm/yyyy, that is the user's birthdate (Brazilian date
> format). So my birthday date would be 31/03/1982 . The problem is that
> MySQL saves dates in the yyyy/mm/dd format, so I need to convert the birth
> date to MySQL's format.
> Does anybody have a function?




More information about the thelist mailing list