Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

inserting date into mysql

New Here ,
May 08, 2010 May 08, 2010

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

TOPICS
Server side applications
374
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 09, 2010 May 09, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 09, 2010 May 09, 2010
LATEST

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

Thanks Greg.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines