[wp-hackers] Internal representation of time

James Davis james at freecharity.org.uk
Fri Mar 14 14:19:21 GMT 2008

(see http://trac.wordpress.org/ticket/2149)

WordPress appears to be a little confusing with it's internal 
representation of time. Times are stored in MySQL as the DATETIME type 
but manipulated internally by converting DATETIME to Unix time stamps, 
which can be easily manipulated with PHP.

The range of dates which can be represented by Unix timestamps 
(1901-12-13 to 2038-01-18) is a small subset of the range of dates which 
can be represented by MySQL DATETIME (1000-01-01 to 9999-12-31).

At the moment entering a date outside of Unix timestamp range results in 
the correct date being stored (sometimes!) in the database but presented 
as 1970-01-01 to the user.

Which range of dates should we expect WordPress to be able to handle? 
Manipulating DATETIME values in PHP is tricky but can be worked around 
by asking MySQL to do the calculations for us.

We could even go so far as to use something like PEAR's Date package.

I guess that leaves us with three options

- Stick to Unix timestamps. Stricter validation to handle input outside 
the valid range. This requires least change to the code.
- Switch completely to MySQL timestamps. Stricter validation ...
- Use an outside library to handle time.

I'm equally happy with any approach, and coding a patch for it, but 
what's the feeling on the list?


http://www.freecharity.org.uk/ - Free IT services for charities
http://www.freecharity.org.uk/wiki/ - The VCSWiki

More information about the wp-hackers mailing list