Jump to content

DateTime Fatal error: Uncaught exception 'Exception'


webguy262

Recommended Posts

Gett an error from some custom code I inherited in a WordPress installation.

 

Here is the error...

 

Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct() [<a href='datetime.--construct'>datetime.--construct</a>]: Failed to parse time string (--) at position 0 (-): Unexpected character' in /home2/history8/public_html/bee/wp-content/themes/makinghistoryblue/beeteachers.php:27 Stack trace: #0 /home2/history8/public_html/bee/wp-content/themes/makinghistoryblue/beeteachers.php(27): DateTime->__construct('--') #1 /home2/history8/public_html/bee/wp-includes/plugin.php(395): bee_teachers('') #2 /home2/history8/public_html/bee/wp-admin/admin.php(151): do_action('bee_teachers', Array) #3 {main} thrown in /home2/history8/public_html/bee/wp-content/themes/makinghistoryblue/beeteachers.php on line 27

 

Here is the code...

 

<?php
$teachers = $wpdb->get_results("SELECT * FROM bee_teachers,bee_postmeta WHERE bee_teachers.statebee=bee_postmeta.post_id and meta_key='regional_date' ORDER BY meta_value ASC");
$today = new DateTime();
foreach ($teachers as $teacher):
	$site = get_post($teacher->statebee)->post_title;
	$date = new DateTime($teacher->meta_value); // this is line 27, mentioned in the error
	if($date<$today) $style=' style="color:#999"';
	else $style='';
?>

 

If I remm out these lines, the query works, just no styling difference based upon date...

 

$date = new DateTime($teacher->meta_value); // this is line 27, mentioned in the error
	if($date<$today) $style=' style="color:#999"';
	else $style='';

 

Thoughts?

 

Link to comment
Share on other sites

What is the value $teacher -> meta_value being returned?  It looks like it has some invalid characters in it from reading the error message (invalid in the sense that they aren't correct for a Date Time.

 

Can we see a sample echo of the value?

 

~juddster

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.