Possible Duplicate:
php date compare
I have a date that I take from the mySQL database that looks like this:
2011-06-20
And I get the date of the current day in this way:
$todaydate = date('Y-m-d');
What I need to know is how do I compare the two results?
How can I compare the dates and understand for example if a week is passed from the database date or a month or a year..etc..?
Thank you!!
There is no need to put that burden on PHP when MySQL has built-in functionality for that already. You should take a look at MySQL’s
DATEDIFF()function:An example of two dates that’d give a 7-day difference could be:
This means that the first date occured -7 days after the first date; that’s 7 days before. If you let the two arguments switch place, the result would be a positive 7.