Did anyone else had this strange problem? Error message:
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (01/18/2016 00:00 AM America/New_York) at position 17 (A): The timezone could not be found in the database'
Exception: DateTime::__construct(): Failed to parse time string (01/18/2016 00:00 AM America/New_York) at position 17 (A): The timezone could not be found in the database
Original PHP Code:
$datetime = new DateTime(trim(html_entity_decode($this->input->post('publish_date').' '.$_POST['schedule_time'].' '.$_POST['schedule_meridian'] . ' ' .$_POST['schedule_timezone'])));
$date = $datetime->format('D, d M Y H:i:s O');
A time zone offset specifies the zone offset from UTC for a time or datetime value. The time zone offset can be represented as [+|-] hh:mm: hh is two digits that range from 00 to 14 and represent the number of hours in the time zone offset.
Databases will convert any datetime into a UTC epoch to store internally. However, some databases may enable storing timezone information. If that's the case, it's recommended to convert all dates to UTC before storing. Don't use local timezone.
The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values in ' YYYY-MM-DD hh:mm:ss ' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59' . The TIMESTAMP data type is used for values that contain both date and time parts.
I afraid you've created DateTime object like this:
$date = new DateTime('01/18/2016 00:00 AM America/New_York');
That is not a supported/valid datetime format!
If you want to create a DateTime object from another format you must call DateTime::createFromFormat() instead, look:
$timezone = new DateTimeZone('America/New_York');
$strdate = '01/18/2016 00:00 AM';
$date = DateTime::createFromFormat('m/d/Y H:i A', $strdate, $timezone);
PHP doc states:
DateTime::createFromFormat / date_create_from_format — Returns new DateTime object formatted according to the specified format
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With