Skip to main content
Participant
May 9, 2010
Question

inserting date into mysql

  • May 9, 2010
  • 2 replies
  • 382 views

I apologize if this has been asked and I did not find it.

I'm using CS4 (php, mysql).

I have a form with a date field that is being inserted into a date field in mysql. I know mysql uses 2010-5-8 format which is fine. But I would like to be able to input the date 5/8/2010 or April 8, 2010 into my form and have it convert to the mysql format when i hit the submit button.

What code should i use, php or mysql to do the conversion? And where should the code go? Examples would be great!

It seems I have searched everyplace but have not found what I think I need.

Many Thanks in Advance

Greg

This topic is closed to new replies. Start a new post to keep the conversation going.

2 replies

May 9, 2010

Hi there,

I use this code to insert the date in the MySQL format:

//I take the dd/mm/yyyy date and convert it into an array and then into 3 variables. After that I convert them to yyyy/mm/dd

     list($day,$month,$year)=explode("/",$_POST['the_name_of_your_date_field']);
     $date="$year/$month/$day";

Then your query should look like:

$query = "INSERT INTO your_DB.t_your_table (the_name_of_your_date_field) ".
"VALUES ('$date')";

Hope it helps

GHossSAuthor
Participant
May 9, 2010

thanks. i'll give that a try tonight when i get home.

Thanks Greg.