Page 1 of 1

Date Comparison

Posted: Tue Mar 16, 2010 2:48 pm
by manderg
Hi,

I have an if statement that is checking the current date and time against a date and time in the future that is a cut off point.

if ($currentDateTime > $lastDateTime)

I have a problem that I think it isn’t being broken down fully, when the $lastDateTime is the next month (04-04-2010) and $currentDateTime date is (16-03-2010) it says the cut off point has been and gone. If I change the $lastDateTime (17-04-2010) then it works.

Has anyone got any idea what I need to do to get it to check the whole date in one?

Thanks,

Graham

Re: Date Comparison

Posted: Tue Mar 16, 2010 2:55 pm
by John Cartwright
If you want to compare dates as strings, you would need to be in the following format - YYYYMMDD so it can be logically sorted.

To work around this issue with your format, you would need to convert your date into a timestamp and compare that (or change the format).

Code: Select all

if (strtotime($currentDateTime) > strtotime($lastDateTime))