Page 1 of 1

compare two dates?

Posted: Sat Dec 27, 2003 6:51 am
by lazersam
Hi
Can anyone suggest how I might get two dates and determine which one is the latest?

for example;

$date1 = "27 of December 2003, at 1.44 pm"
$date2 = "01 of January 2004, at 1.44 pm"

How can I see if $date2 is later than $date1?

Do you think this is a good way.. and could I write it better?

Code: Select all

<?php
	
                #Todays Date
	$date1 = gmdate("U",time ());
	
	#Make a date 30 days ahead
	$date2 = gmdate("U",mktime(date(H) + 24 * 30 ));
	
	#Do the test.
	If (   $date1 > $date2  ){
	echo "date1 > date2";
	exit ();
	}

?>
Regards

Lawrence.

Posted: Sat Dec 27, 2003 7:24 am
by devork
convert the dates into timestamp
the latest date will have high timestamp than the earlier one .