Re: Difference between 2 Dates

From: Date: Fri, 13 Dec 2002 22:49:31 +0000
Subject: Re: Difference between 2 Dates
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-128219@lists.php.net to get a copy of this message
On Fri, 13 Dec 2002, Colin Bossen wrote: > I have a similar problem. I am trying to figure out which of two dates > is greater. Both are in the yyyy-mm-dd format. Is there any easy > function that allows this sort of comparison or am I missing something? You have a simpler problem. yyyy-mm-dd is the ISO format, and one of the reasons it is a great format is, you can sort it any way you like, and it just works. So the simplest way to do it is to compare strings in alphabetic order: if($a<$b) echo "$a earlier than $b\n"; else echo "$b earlier than $a\n"; Cheers, Jean-Marc Libs -- Give a man a fish and he will eat for a day. Teach a man to fish and he will sit in a boat drinking beer all day.

« previous php.general (#128219) next »