galvin Posted May 23, 2010 Share Posted May 23, 2010 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. Link to comment https://forums.phpfreaks.com/topic/202620-comparing-dates-in-php-to-see-which-one-is-later/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 23, 2010 Share Posted May 23, 2010 One of the reasons for the YYYY-MM-DD format is because you can do greater-than/less-than comparisons and sorting on the values. Link to comment https://forums.phpfreaks.com/topic/202620-comparing-dates-in-php-to-see-which-one-is-later/#findComment-1062102 Share on other sites More sharing options...
galvin Posted May 23, 2010 Author Share Posted May 23, 2010 well that solves that, great to know going forward, thanks a lot!!! Link to comment https://forums.phpfreaks.com/topic/202620-comparing-dates-in-php-to-see-which-one-is-later/#findComment-1062216 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.