Warning: count(): Parameter must be an array or an object that implements Countable in /home/u100541/public_html/deflorence.com/wp-content/plugins/page-and-post-lister/cg_pages_core.php on line 390

wordpress and the unix date format

4 March 2010 - WordPress

i encountered an interesting fluke in converting Lutecium, a site of which i am co-curator, from HTML to WordPress 2.91.  A psychoanalytical archive, the site has in excess of 1500 documents, some of them dating back to 1926. From our users point of view,  it made sense to have the publishing date of each article set to that of the original publishing date of the document.  So far so good, and the site owner, Jacques Siboni, ran a quick script on a CSV file of the content which was then imported into WordPress db.

Then something strange started to happen. Some of the articles would be displayed with their correct date, and therefore in the correct order. But some of them would be displayed with today’s date, and therefore in the wrong order. We scratched our heads, examined the theme files, checked the forums, but to no avail.

Then Jacques, a bit of a Linux geek, noticed that the files exhibiting a date disorder had dates prior to 1970. Bingo, it had to do with the Unix file date format, which counts the number of milliseconds elapsed since 1st January 1970. Stupid but true. This returns a positive integer, which is then decoded to the DDMMYYY format. Therefore, any DDMMYYYY date prior to 1970 converted to the Unix format will become a negative integer.

Still, that did not explain everything. Why would WordPress convert a negative integer to today’s date? That’s because since version 2.8, the_date() function checks if the Unix integer is negative, and if it is, it returns today’s date. It’s all explained on the WordPress Trac site.

So if in your db you have articles dated prior to 1970, then in /wp-includes/functions.php uncomment lines 89-98. You will then obtain the proper date of your articles.

Well done us!

A cause de spam trop nombreux, les commentaires sont fermés-envoyez tout commentaire par mail à bdeflorence@gmail.com ou bien apportez votre parole au groupe de discussion the-letter sur google group.