writing dates to mysql db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mxrideruk
Forum Newbie
Posts: 2
Joined: Mon Jan 08, 2007 7:37 am

writing dates to mysql db

Post 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
hmsg
Forum Commoner
Posts: 42
Joined: Sun May 14, 2006 9:48 am

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
Post Reply