Page 1 of 1

Comparing two dates

Posted: Fri Mar 07, 2003 3:50 am
by terji
I need to compare two dates to see which one is newer. What am I doing wrong in this example:

Code: Select all

$date1 = date("d-m-y H.i", mktime(0, 0, 0, 2, 3, 2003));
$date2 = date("d-m-y H.i", mktime(0, 0, 0, 2, 4, 2003));

if($date1 < $date2)
{
     print("date2 is newer than date1");
}
I'm I totally going in the wrong direction here or what?

Posted: Fri Mar 07, 2003 4:11 am
by pootergeist
lose the date() bit so you are just comparing timestamps and not strings

$date1 = mktime(0,0,0,2,3,2003);

Posted: Fri Mar 07, 2003 4:13 am
by twigletmac
Exactly - compare the timestamps and save the formatting for when you display the data.

Mac

Thx

Posted: Fri Mar 07, 2003 4:16 am
by terji
Thank you! Works like a charm....