Jump to content

Comparing dates in PHP to see which one is later?


galvin

Recommended Posts

Can anyone guide me to a tutorial or just tell me (if it's easier than I think it is :) ) of how you can take two dates in PHP (we'll call them $date1 and $date2) and compare them to see if date1 is BEFORE or AFTER date 2?

 

Is there a simple way to do this, or do they have to be broken down to seconds and THEN compared (like if the date1 second total is higher than the date2 second total, then we know it comes AFTER date2).

 

FYI, my dates are stored in mysql as type "date" (i.e. in the format of XXXX-XX-XX)

 

Any help would be appreciated, thanks much!

 

-Greg

 

ADD-ON:  If I just have $date1 and $date2 and they are both in the same format  from mysql (i.e.  type "date"), then can I just explicitly say "if ($date1 > $date2)"?

 

I just tried this and it seems to be working but I didn't think that would work that easily.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.