Closed (won't fix)
Project:
Date
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
23 Mar 2007 at 23:44 UTC
Updated:
19 Aug 2010 at 00:37 UTC
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
Comment #1
karens commentedThe 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.
Comment #2
arlinsandbulte commentedI 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.