Page 1 of 1

date compare

Posted: Mon Aug 11, 2003 10:02 pm
by theclay7
if I want to compare today's date to August 12, 2003, can I use the if statement as follow, because I check and it works fine, but someone suggests me that "12082003" is a string and it is not going to work okay....

can some help? and any better alternatives?


$datenow = date("dmY");
echo "date today is ".$datenow."<BR>";

if ($datenow > "12082003")
echo "date today is greater than August 12, 2003";
else
echo "date today is smaller than August 12, 2003";

:arrow:

Posted: Mon Aug 11, 2003 10:22 pm
by Bennettman
Try this:

Code: Select all

<?

echo "date today is " . date("dmY") . "<br />";

if (time() > strtotime("12 August 2003")) {
     echo "date today is greater than August 12, 2003";
}
else {
     echo "date today is smaller than August 12, 2003";
}

?>
Alternatively, replace strtotime("12 August 2003") with the UNIX timestamp of that date which you can get by parsing strtotime("12 August 2003").

Posted: Mon Aug 11, 2003 10:24 pm
by JAM
Follow up...

Yes, its a string... And youre problems will start at the beginning of next month...

Your: 12082003 = 12day, 08month, 2003year

So the 1st of september would give you: 01092003
So the date is bigger, but the value is smaller, so comparing with a < is a nogo...