Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

[Errors] - DateTime::__construct(): Failed to parse time string 9 years 3 months ago #16211

  • Bluefox
  • Bluefox's Avatar Topic Author
  • Offline
  • Moderator
  • Moderator
  • Posts: 4529
  • Thank you received: 493
just some info explaining why the message happens.
 DateTime::__construct(): Failed to parse time string (Mon, 5. January 2015 04.08.AM) at position 27 (A): The timezone could not be found in the database

within the page we're using code like
$result['startDateTime'] = 'Mon, 5. January 2015 04.08.AM';
$start		= new JDate($result['startDateTime']);
$start_day	= $start->format('m-d-Y');

JDate doesn't like the input other then the formats of php Date and in this case it doesn't like the text of 2 characters. When using UTC or something like that it it will recognize the timezone and will not trow in the error.

but to solve the above the AM should be stripped to something like this
$result['startDateTime'] = 'Mon, 5. January 2015 04.08';
$start		= new JDate($result['startDateTime']);
$start_day	= $start->format('m-d-Y');


so when using the JDate function make sure that the input is correct as you will get an unfriendly error notice if it's used incorrectly.
Attachments:

Please Log in or Create an account to join the conversation.

Last edit: by Bluefox.

[Errors] - DateTime::__construct(): Failed to parse time string 9 years 3 months ago #16216

  • Bluefox
  • Bluefox's Avatar Topic Author
  • Offline
  • Moderator
  • Moderator
  • Posts: 4529
  • Thank you received: 493
to add:

JDate->format will at default set a timezone as the function includes this.
// If the returned time should not be local use GMT.
if ($local == false)
{
	parent::setTimezone(self::$gmt);
}

if ($local == false)
{
	parent::setTimezone($this->tz);
}

if you set the value to true it might solve the problem also
$value = new JDate($date);
$value = $start->format('m-d-Y', true);

Please Log in or Create an account to join the conversation.

Last edit: by Bluefox.
  • Page:
  • 1
Time to create page: 0.233 seconds

Donate

If you find JEM useful and if you use it on your site, please consider a donation to the project.

Private Messages

You are not logged in.

Follow us......