webguy262 Posted October 9, 2011 Share Posted October 9, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/248746-datetime-fatal-error-uncaught-exception-exception/ Share on other sites More sharing options...
awjudd Posted October 9, 2011 Share Posted October 9, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/248746-datetime-fatal-error-uncaught-exception-exception/#findComment-1277460 Share on other sites More sharing options...
webguy262 Posted October 9, 2011 Author Share Posted October 9, 2011 you're right... the date never went into the dbase correctly. Quote Link to comment https://forums.phpfreaks.com/topic/248746-datetime-fatal-error-uncaught-exception-exception/#findComment-1277539 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.