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?

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.