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
Date Comparison
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Date Comparison
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).
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))