Skip to content

Date troubles in WordPress

It seems the following code

mysql2date('Y', $post->post_date)

works incorrectly in WordPress for dates before January 1st 1970, as it returns current year instead of the post date.

It this case it can be fixed easily with this replacement:

substr($post->post_date, 0, 4)

That is enough to make the OnThisDay plugin to show correctly the records about historical events in the past.

Leave a Reply

Your email address will not be published.