Page 1 of 1
PHP Date Conversion
Posted: Fri Aug 13, 2010 10:38 pm
by webphotogeek
Can someone tell me how to convert a date such as 8/13/10 into the the MySQL format, such as 2010-08-13 and also the reverse using PHP? I can't seem to find the right functions.
Thanks!
Re: PHP Date Conversion
Posted: Fri Aug 13, 2010 11:59 pm
by arrielmabale
//convert to sql
$mDate = 8/13/10
$edate = explode('/',$mDate);
$toSql = '20' + $edate[2] + '-' + $edate[1] + '-' + $edate[0];
##############
//from sql make sure to used UNIX_TIMESTAMP on the field
//then top display
$mdate = date('y/m/d');
i did not see the output, but im sure of this
Re: PHP Date Conversion
Posted: Sat Aug 14, 2010 6:15 am
by webphotogeek
Thanks for the reply. I didn't think of using the explode function

Re: PHP Date Conversion
Posted: Sat Aug 14, 2010 9:49 am
by Weirdan
Code: Select all
$mDate = "8/13/10";
$toSql = DateTime::createFromFormat("m/d/y", $mDate)->format("Y-m-d");