Page 1 of 1

writing dates to mysql db

Posted: Fri Feb 02, 2007 9:20 am
by mxrideruk
hi,
i'm trying to write a date from a text input in a form to a date column in a mysql db but it only works if my client enters it as 2007-01-01.
anyone know how change the input so i can get my clients to enter it as 01-01-2007
cheers
kev

Posted: Fri Feb 02, 2007 9:24 am
by hmsg
you can change the date after get it
you can do explode('-',$date), this makes a array position 0 - the year, position 1 - the month, and possition 2 - the day

then just do $newdate= $array[2]."-".$array[1]."-".$array[0]

Posted: Fri Feb 02, 2007 9:27 am
by feyd
Take a look at the many varying implementations to date pickers floating around. I would recommend using one of those instead of a blind text field.

Posted: Fri Feb 02, 2007 10:55 am
by RobertGonzalez
You can also change your default format for the data field in the MySQL table and use the MySQL date functions to get it the way you want.