Overview
If you are working on a WordPress site and encounter the following error while creating posts or WooCommerce products:
Warning: strtotime(): Epoch doesn’t fit in a PHP integer in
wp-admin/includes/meta-boxes.php
on line 381.
This issue often arises due to invalid date values, such as 0000-00-00 00:00:00
, in the WordPress database. This article will guide you through resolving the problem effectively.
The Cause
The error occurs because the PHP strtotime()
function cannot handle invalid date strings like 0000-00-00 00:00:00
. When the WordPress core attempts to process such dates, it triggers this error.
Steps to Fix the Error
1. Update the PHP Code
Browse your WordPress directory and edit line# 381 in meta-boxes.php file. The location will be wp-admin/includes/meta-boxes.php
. Replace the existing condition as shown below:
if ( ! empty( $post->post_date_gmt ) && time() < strtotime( $post->post_date_gmt . ' +0000' ) ) :
With the following:
if ( ! empty( $post->post_date_gmt ) && $post->post_date_gmt !== '0000-00-00 00:00:00' && time() < strtotime( $post->post_date_gmt . ' +0000' ) ) :
This modification ensures the condition checks for invalid date values before processing. If the error still persists, then refer to the step# 2.
2. Verify and Update Database Entries
If the error persists, you might have invalid date entries in your database. Run the following SQL query in your database tool (e.g., phpMyAdmin):
SELECT * FROM wp_posts
WHERE post_date_gmt = '0000-00-00 00:00:00'
OR post_modified_gmt = '0000-00-00 00:00:00'
OR post_date = '0000-00-00 00:00:00'
OR post_modified = '0000-00-00 00:00:00';
This query identifies entries with invalid date values.
3. Replace Invalid Dates
Replace the invalid dates with a valid dummy date, such as 1970-01-01 00:00:00
. Use an SQL UPDATE
statement, for example:
UPDATE wp_posts
SET post_date_gmt = '1970-01-01 00:00:00',
post_modified_gmt = '1970-01-01 00:00:00'
WHERE post_date_gmt = '0000-00-00 00:00:00'
OR post_modified_gmt = '0000-00-00 00:00:00';
Sometimes, updating the entries using SQL query is not successful. An alternative option is to export the database, open in a text editor and replace all the entries '0000-00-00 00:00:00'
with '1970-01-01 00:00:00'
. You can then import the database.
Thanks for this amazing blog! very helpful and sorted the issue.