Date Comparison

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
manderg
Forum Newbie
Posts: 1
Joined: Tue Mar 16, 2010 2:40 pm

Date Comparison

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Date Comparison

Post 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))
Post Reply