adzie Posted August 1, 2009 Share Posted August 1, 2009 Hello folks, Date difference again, I only post this as there is very little resource available on this when searching. I want to perform a certain action if a date is more than 28 days or similar so. $record produces the date 2009 - 07 -31. Any direction appreciated. If $record > 28 days { echo "no test"; }else{ echo "test"; } Quote Link to comment https://forums.phpfreaks.com/topic/168421-date-difference/ Share on other sites More sharing options...
ignace Posted August 1, 2009 Share Posted August 1, 2009 $strtotime = strtotime($row['date']); $now = time(); $diff = $now - $strtotime; if ($diff > 2419200/*28 days in time*/) { echo 'no test'; } else { echo 'test'; } Quote Link to comment https://forums.phpfreaks.com/topic/168421-date-difference/#findComment-888438 Share on other sites More sharing options...
adzie Posted August 3, 2009 Author Share Posted August 3, 2009 ignace thanks for that. Is there a way without changing to strtotime? many thanks Quote Link to comment https://forums.phpfreaks.com/topic/168421-date-difference/#findComment-889776 Share on other sites More sharing options...
gevans Posted August 3, 2009 Share Posted August 3, 2009 There's always other ways to do things, but that is a very straight forward way to do it... Another option would be to explode your date to seperate the year, month and day. Then comapre the day to the current day, compare the month to the current month and year to the current year. Then work you're way through the difference in the day, if it's less than 28 see if the months are different, if they're not check if the years are different, if not then its less than 28 days. Quote Link to comment https://forums.phpfreaks.com/topic/168421-date-difference/#findComment-889962 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.