Title: PHP Fatal error: Uncaught Exception: DateTime::__construct()
Last modified: April 25, 2017

---

# PHP Fatal error: Uncaught Exception: DateTime::__construct()

 *  Resolved [linkate](https://wordpress.org/support/users/linkate/)
 * (@linkate)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/php-fatal-error-uncaught-exception-datetime__construct/)
 * The plugin was throwing this error:
 * _PHP Fatal error: Uncaught Exception: DateTime::\_\_construct(): Failed to parse
   time string (9 marzo, 2017) at position 5 (z): The timezone could not be found
   in the database in /httpdocs/wp-content/plugins/cache-control/cache-control.php:
   191_
 * **The page was returning a HTTP 500 Internal server error showing the white screen
   of death.**
 * At cache-control.php line 191, i have seen:
 *  `$date_mod = new DateTime( get_the_modified_date() );`
 * A date object is created from the string retrieved by get_the_modified_date()
 * At wordpress codex we can read that get_the_modified_date( $d, $post ) returns(
   string) the date on which the post was last modified. The function parameters
   are both optional and $d in particular is (string) (optional) Optional PHP date
   format. Defaults to the “date_format” option.
 * My wordpress installation is in Spanish and the date_format option is by default
   j F, Y. The date string retrieved by get_the_modified_date is not valid to create
   a new DateTime object.
 * To ensure that the $date_mod DateTime object is correctly created for any possible
   date_format option value, i have changed the line to this:
 * `$date_mod = new DateTime( get_the_modified_date( 'Y-m-d' ) );`
 * That way we ensure that the value retrived by get_the_modified_date is alwais
   going to be correct to create the $date_mod DateTime object no matter the date_format
   option value.
 * Here is the patch to fix the issue:
 *     ```
       Index: trunk/cache-control.php
       ===================================================================
       --- trunk/cache-control.php	(revision 1645039)
       +++ trunk/cache-control.php	(working copy)
       @@ -205,7 +205,7 @@
   
            if ( $option_name == 'singles' && get_option( 'cache_control_singles_mmulti' ) == 1 ) {
                $date_now = new DateTime();
       -        $date_mod = new DateTime( get_the_modified_date() );
       +        $date_mod = new DateTime( get_the_modified_date( 'Y-m-d' ) );
   
                $last_com = get_comments( 'post_id=' . get_the_ID() . '&number=1&include_unapproved=1&number=1&orderby=comment_date' );
                if ( $last_com != NULL ) {
       ```
   

Viewing 1 replies (of 1 total)

 *  Plugin Author [Dan](https://wordpress.org/support/users/geekysoft/)
 * (@geekysoft)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/php-fatal-error-uncaught-exception-datetime__construct/#post-9070142)
 * Thank you for notifying me about this issue an suggesting a patch. The issue 
   should be resolved in the latest release, version 2.0.2. It may take some hours
   before everyone gets the update, but you should have it within a day.

Viewing 1 replies (of 1 total)

The topic ‘PHP Fatal error: Uncaught Exception: DateTime::__construct()’ is closed
to new replies.

 * ![](https://ps.w.org/cache-control/assets/icon-256x256.png?rev=1632145)
 * [Cache-Control](https://wordpress.org/plugins/cache-control/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cache-control/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cache-control/)
 * [Active Topics](https://wordpress.org/support/plugin/cache-control/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cache-control/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cache-control/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Dan](https://wordpress.org/support/users/geekysoft/)
 * Last activity: [9 years, 1 month ago](https://wordpress.org/support/topic/php-fatal-error-uncaught-exception-datetime__construct/#post-9070142)
 * Status: resolved