Re: date conversion from access to mysql
Posted by:
Aaron Cruz
Date: September 17, 2009 04:55AM
hi sally,
I am a little confused on which program is causing the problem but here's what you can do either way.
Take the foreign date, let's say 2009-11-07(yyyy-dd-mm)
//turn date into array
$date = explode('-','2009-11-07');
//make a valid time stamp at 0 time in the correct order(month,day,year)
$newdate = mktime(0,0,0,$date[2],$date[1],$date[0]);
//create a new date in the your original format(yyyy-mm-dd)
$formatted_date = date('Y',$newdate)."-".date('m',$newdate)."-".date('d',$newdate);
echo "the new, formatted date = ".$formatted_date;
here is another way using substring
$date = '2009-11-07';
$year = substr($date,0,4);
$date = substr($date,5);
$date = explode('-',$date);
$newDate = $year."-".$date[1]."-".$date[0];
echo "<br>The new, formatted date = ".$newDate;
Hope this helps. The second way is probably faster but the first way sticks with date formats if that is important to you. Viel Spaß!