My apologies if this has been covered, I did a search but nothing came up.

I have a DATE column in a MySQL database (format yyyy-mm-dd), I would like to be able to extract each component of the date and make it a seperate variable in PHP. This would end up with

$day = "dd"
$mon = "mm"
$yea = "yyyy"

I hoped there would be something similar to Perl's regular expressions or maybe there would be specific functions for splitting date strings but, so far, no joy.

Thanks for any help

Chris

    Hi Chris

    MySQL will indeed do this for you. The info is at http://www.mysql.com/doc/en/Date_and_time_functions.html

    To get the day number, you want %d (two digit day of month)

    To get the month, you want %m (two digit month of year)

    To get the year, you want %Y (four-digit year)

    Pay attention to upper/lower case - it makes a big difference :-)

    HTH

    Norm

      Excellent, that's just what I needed.

      I guess I didn't really know what to search for.

      Cheers

      Chris

        Originally posted by Norman Graham
        Pay attention to upper/lower case - it makes a big difference :-)

        you name it.😉

          Write a Reply...