it'd be nice if there was a function in date.inc that allowed you to compare 2 dates. possible prototype:

/**
 * Compare two dates and indicate their relative ordering.
 *
 * @return
 *   -1 if $date1 is earlier than $date2, 0 if they're the same, and 1 if $date1 is later than $date2
 */
int date_compare($date1, $date2) {
  ...
}

this is just like strcmp() for folks who are used to that (http://us2.php.net/manual/en/function.strcmp.php if you're not). alternatively, it could be 2 functions (date_equals() and date_earlier() or something), but i think a single function with -1, 0, or 1 would be cleaner (and less code to deal with in date.inc).

this would be handy for http://drupal.org/node/128602 and also other things trying to use DateAPI to do date-based logic.

thanks!
-derek

Comments

karens’s picture

Version: 5.x-1.x-dev » 7.x-1.x-dev

The new Date API in HEAD now has a date_diff() function that will allow you to find the difference between two dates using whatever measure you like -- seconds, minutes, hours, days, months, or years.

It doesn't return true or false as to which is larger though, so I guess this is a different request. Anyway, this will be done in HEAD if it gets added.

arlinsandbulte’s picture

Status: Active » Closed (won't fix)

I am going to mark this as "won't fix" because I think date_diff() covers this and there are other ways to do this with just a bit of simple code.

Also #128602: Theme changes - gray out days in past referenced above has been resolved.