Comparing Dates

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
dwessell
Forum Commoner
Posts: 62
Joined: Fri Dec 23, 2005 2:30 pm

Comparing Dates

Post by dwessell »

Hi all.. It would seem that MySQL 4 stores dates as yyyy-mm-dd.. Can someone suggest their preferences for comparing a date retrieved from MySQL with the local server date.

Thanks
David
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You can convert the date to a unix timestamp and compare that against time(). Or you can select MONTH(date_field), DAY(date_field) and YEAR(date_field) from MySQL and compare each of those to date("M"), date("D") and date("Y).

There are probably other, better ways to do it as well. Off the top of my head I would be inclined to select the date as it is in MySQL and compare that to date("Y-M-D") in PHP.
Post Reply