Re: comparing dates works sometimes and fails another time!
| From: | trogers | Date: | Thu, 29 Mar 2001 16:13:55 +0000 |
| Subject: | Re: comparing dates works sometimes and fails another time! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-46108@lists.php.net to get a copy of this message | ||
You are doing a string compare not date, convert them to a unix time stamp and then compare
$d1 = explode("-",$date1);
$d2 = explode("-",$date2);
$ts1 = mktime(0,0,0,$d1[1],$d1[2],$d1[0]);
$ts2 = mktime(0,0,0,$d2[1],$d2[2],$d2[0]);
if( $ts1 > $ts2 ):
echo "Date 1 is greater than date2";elseif($ts1 == $ts2):
echo "date 1 is equal to date 2" ;else:
echo " date 2 is greater than date 1";endif; should work :) Tom At 09:50 AM 28/03/01 +0000, kaab kaoutar wrote:
Hi! $date1="2001-1-7";$date2="2001-1-14"; if ($date1>=$date2) echo "date1 is greater then date2"; else echo "date2 is greater then date1"; the result is the first :( but it works for other dates! Thanks _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net