Alex Rivera | Logout

How to convert MM/DD/YYYY to YYYY-MM-DD?

Asked 2010-07-20T08:38:33.740
27

I have a jquery calendar that sets the input value to MM/DD/YYYY

How would I convert it so that my database column (date) can accept it correctly?

EDIT

Gordon was right - his link pointed me to this answer

$mysql_date = date('Y-m-d H:i:s', strtotime($user_date));
Edit
Report

2 Answers

2

We need more information?

1) What script is inserting into database? I am assuming PHP

2) Also we need to know how you are storing the date and in what format?

My solution would be:

$dates = preg_split('/\//',$_POST['date']);

$month = $dates[0];
$day = $dates[1];
$year = $dates[2];

$finalDate = $year.'-'.$month.'-'.$day;
answered 2010-07-20T08:45:59.000
2

Alternatively you can do this without using the explode:

$date = "12/25/2010";
$mysql_date = date('Y-m-d', strtotime($date));

You can now use $mysql_date to insert into your database.

answered 2010-07-20T08:56:26.330

Your Answer