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 )";
}else{
	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!

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.

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.
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.