Andy-H Posted July 20, 2008 Share Posted July 20, 2008 How can I find the difference in days, months and years between two given timestamps (yyyy-mm-dd hh:mm:ss). Ty for any help Quote Link to comment https://forums.phpfreaks.com/topic/115696-solved-comparing-dates/ Share on other sites More sharing options...
papaface Posted July 20, 2008 Share Posted July 20, 2008 Answered many many many many many many many many many many many many many many many many many many many many many many many many many many many many many many many many many many many many many many many many many many many times. Try google or forum search: http://www.google.co.uk/search?q=compare+dates+%2B+php&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a Quote Link to comment https://forums.phpfreaks.com/topic/115696-solved-comparing-dates/#findComment-594828 Share on other sites More sharing options...
l0ve2hat3 Posted July 20, 2008 Share Posted July 20, 2008 $exp_date = "2006-01-16"; $todays_date = date("Y-m-d"); $today = strtotime($todays_date); $expiration_date = strtotime($exp_date); if ($expiration_date > $today) { $valid = "yes"; } else { $valid = "no"; } Quote Link to comment https://forums.phpfreaks.com/topic/115696-solved-comparing-dates/#findComment-594836 Share on other sites More sharing options...
Andy-H Posted July 20, 2008 Author Share Posted July 20, 2008 Thankyou, also do you know of any way I can add a month to the date from date('Y-m-d'); without having to explode it and go through if statements to make it add years instead of going to 13 etc. ??? Quote Link to comment https://forums.phpfreaks.com/topic/115696-solved-comparing-dates/#findComment-594854 Share on other sites More sharing options...
cooldude832 Posted July 20, 2008 Share Posted July 20, 2008 if it goes to 13 the computer sense the date infraction and alters it to add a year and subtract 12 months look at strtotime <?php $today = date("Y-m-d"); $next_month = date("Y-m-d",strtotime("+1 month",$today)) echo "Today is: ".$today."<br />Next month is: ".$next_month; ?> Quote Link to comment https://forums.phpfreaks.com/topic/115696-solved-comparing-dates/#findComment-594863 Share on other sites More sharing options...
Andy-H Posted July 20, 2008 Author Share Posted July 20, 2008 Today is: 2008-07-20 Next month is: 1970-01-31 lol :S Quote Link to comment https://forums.phpfreaks.com/topic/115696-solved-comparing-dates/#findComment-594866 Share on other sites More sharing options...
cooldude832 Posted July 20, 2008 Share Posted July 20, 2008 oops because i didn't use a valid date in UNIX timestamp for the second parameter in my strtotime try <?php $today = date("Y-m-d"); $next_month = date("Y-m-d",strtotime("+1 month",strtotime($today))) echo "Today is: ".$today."<br />Next month is: ".$next_month; ?> Putting today in the strtotime is not needed because default is the current time if no parameter is set, but I wanted to show u can put one in. Quote Link to comment https://forums.phpfreaks.com/topic/115696-solved-comparing-dates/#findComment-594869 Share on other sites More sharing options...
Andy-H Posted July 20, 2008 Author Share Posted July 20, 2008 Today is: 2008-07-20 Next month is: 2008-08-20 Thanks :-D Quote Link to comment https://forums.phpfreaks.com/topic/115696-solved-comparing-dates/#findComment-594871 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.