I would like to ask how can I check if a sample date is earlier than another specified one.

I have this:
$Monday = 1-18-2010
$enroll = 12-29-2009

$enroll = $row['enroll'];
if($enroll >= $Monday){
	echo "<br>$enroll is earlier than $Monday this returns TRUE ( 1 )";
	echo "<br>$Monday is earlier than $enroll this returns FALSE ( 0 )";

This returns: 12-29-2009 is earlier than 1-18-2010 this returns TRUE ( 1 ) - THIS IS RIGHT

But when I set $Monday = 11-23-2009, It returns: 12-29-2009 is earlier than 11-23-2009 this returns TRUE ( 1 )

It's obviously wrong. So how can I proceed with this?

Is there a way I can convert my time format from 1-18-2010 to 2010-1-18?

Thank you!

Edited by codewalkz: wrong var

8 Years
Discussion Span
Last Post by webbespoke

Check the mktime() function. Parse your dates in it and it will return the number of seconds since unix epoch, these are just two big numbers which can be easily compared.

Edited by amd_k8: n/a


Please note that I haven't been able to check if the code is working correctly, however it should hopefully give you the idea.

// Hour, Minute, Second, Month, Day, Year
$Monday = mktime(0,0,0,1,18,2010);
$enroll = mktime(0,0,0,29,12,2009);

if($Monday >= $enroll){
	// If $Monday is after or on the same date as enroll.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.