<?php
function compareDates($date1,$date2) {
$date1_array = explode("-",$date1);
$date2_array = explode("-",$date2);
$timestamp1 =
mktime(0,0,0,$date1_array[1],$date1_array[2],$date1_array[0]);
$timestamp2 =
mktime(0,0,0,$date2_array[1],$date2_array[2],$date2_array[0]);
if ($timestamp1>$timestamp2) {
print "The second date is earlier than the first.";
} else if ($timestamp1<$timestamp2) {
print "The first date is earlier than the second.";
} else {
print "The dates are equal.";
}
}
compareDates("2004-03-06","2004-05-06");
// outputs "The first date is earlier than the second."
?>
of course this doesnt test for the validity of the dates (for example if the
user inputs dates via a form and the dates are invalid, an error could
result)
- JP
<jo****@yahoo.com> wrote in message
news:e9**************************@posting.google.c om...
Hi,
How do i compare two date in YYYY-MM-DD format to determine which one is
earlier?
thanks and regards
Jorn