Comparing two ISO8601 dates strings in PHP -


i need compare (actually rank/sort) dates in php script. dates iso-8601 date format i.e.

yyyy-mm-dd

i wrote comparison function splits dates , compares year/month/day. however, seems may overkill , done simple string comparison like:

if ($date1 < $date2)    // elseif( $date1 > $date2)    //do else else    //do yet thing 

is assumption (iso-8601) date string comparison correct - i.e. can rid of function (to save few clock cycles on server), or safer explicity comparison in custom function?

http://en.wikipedia.org/wiki/iso_8601#general_principles

date , time values organized least significant: year, month (or week), day, hour, minute, second, , fraction of second. lexicographical order of representation corresponds chronological order, except date representations involving negative years. allows dates naturally sorted by, example, file systems.

go ahead string sorting. if wikipedia not enough, surely http://www.ietf.org/rfc/rfc3339.txt is, search strcmp in there.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -