Using historical dates in WordPress custom fields

I’ve been working on a family history project in WordPress, which includes a bit of a genealogy. Naturally, no genealogy is complete without important dates, such as birth and death. However, as I moved further back in history, I ran into a particular annoyance that seems to bother many WordPress developers (

A handful of custom date fields were created for this project. They worked well, until I attempted to add an ancestor born in the late 1700’s. The furthest back the date picker allowed was 1902. No bother, I thought, and simply typed the date into the expected format. But, when I clicked Save, the date fields were emptied. Some googling indicated that it was a problem with 32-bit PHP not supporting a large enough negative integer for the strtotime() function to represent a date earlier than 1902. This question on StackExchange has two great answers that include more detail. The problem was, I have 64-bit Apache (which is determined by the PHP constant PHP_INT_SIZE equaling 8).

You might wonder why PHP’s strtotime() function would prevent certain dates from inserting into a date field in MySQL. The important thing to realize is that every custom field’s value is stored as longtext in the wp_postmeta table and not a date field. So, you aren’t saving a date; you are saving a string, that represents and is later displayed as a date.


Considering that PHP’s date/time functions rely on the underlying OS’s date/time functions and the server was running Ubuntu 12.04 (over two years old now), I decided to try an upgrade to Ubuntu 14.04. By the way, here’s a big tip: Upgrade your Linux distro before it reaches End Of Life. Waiting until after makes it a bit of a headache. Anyway, after the upgrade completed, I went back to WordPress and saw that the field was still limited to 1902. So, I updated WordPress to 4.0. That did the trick! I can now go way way way way way back in time. If I studied the problem and release notes of each upgrade more thoroughly, I could probably tell you why, but upgrading Ubuntu and WordPress took care of the problem for me in any case. Just another example of why staying up-to-date is always important.

If someone a bit more versed in WP/Ubuntu changes cares to share further insight, please consider sharing in the comments.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s