I need to be able to convert a string (see example below) to a format that can be added to MySQL. I could just add it as a var car but I need to be able to run queries based on these date ranges.
e.g. '02 May 2013 12:08 AM GMT'
Any suggestion of the best way to achieve this?
EDIT Currently trying the following:
$date = date_create_from_format('d M Y H:i A e', '02 May 2013 12:08 AM GMT');
echo $date;
but getting a server error when I trying echoing the date.
I've also tried the following to break the date and timezone apart and try to deal with it separately:
$myvalue = '02 May 2013 12:08 AM GMT';
$arr = explode(' ',trim($myvalue));
$timezone = new DateTimeZone($arr[5]);
$arr[count($arr)-1]='';
$time=implode(' ',$arr);
$date = date_create_from_format('d M Y h:i A', $time, $timezone);
echo $date;
but again I'm getting a server error.
EDIT I just realized that the second chunk of code might be going wrong due to the GMT as it doesn't appear to be a usable format with this function.
EDIT
After further investigation I think the best way to store the data is to have all dates stored as a DATETIMEin
MySQL with the same timezone (gmt) and along with it storing the actual timezone they are and using the timezone when running queries if needed.
$myvalue = '02 May 2013 12:08 AM GMT';
$arr = explode(' ',trim($myvalue));
$timezone = new DateTimeZone($arr[5]);
$arr[count($arr)-1]='';
$time=implode(' ',$arr);
$timestamp = strtotime($time);
$date = date("Y-m-d H:i:s", $timestamp);
echo $date;