OldWest Posted December 2, 2010 Share Posted December 2, 2010 I am trying to simulate an ad expiration and carry out an action if the ad is expired. And I cannot get the if/else to work properly... I've tried many variations and I cannot see what I am doing wrong here. Any tips please 3 hours and counting of no solution! $ad_start = time()-14 . "<br />"; // 14 days from today in the past (negative) echo $ad_start; $current_time = time() . "<br />"; // current epoch time echo $current_time; $days_past = $ad_start - $current_time; // days past echo "<br />$days_past days have past since the ad started!<br />"; if($days_past <= 14) { echo "<br />Ad is less than 14 days. Not expired."; } else { echo "<br />Ad is over 14 days. Expired."; } Link to comment https://forums.phpfreaks.com/topic/220446-subtract-time-14-from-time-output-not-as-expected-what-am-i-doing-wrong/ Share on other sites More sharing options...
OldWest Posted December 2, 2010 Author Share Posted December 2, 2010 damn i accidentally quoted instead of modified! Link to comment https://forums.phpfreaks.com/topic/220446-subtract-time-14-from-time-output-not-as-expected-what-am-i-doing-wrong/#findComment-1142129 Share on other sites More sharing options...
OldWest Posted December 2, 2010 Author Share Posted December 2, 2010 Ok I was able to get it to work, but I am not sure why the output is showing in negatives. I did this and it seems to work as expected now. Is there a smarter or better way to do this to ensure the time count is exact and accurate? $ad_start = time()-14 . "<br />"; echo $ad_start; $current_time = time() . "<br />"; echo $current_time; $days_past = $ad_start - $current_time; echo "<br />$days_past days have past since the ad started!<br />"; if($days_past >= -14) { echo "<br />Ad is less than 14 days. Not expired."; } else { echo "<br />Ad is over 14 days. Expired."; } Link to comment https://forums.phpfreaks.com/topic/220446-subtract-time-14-from-time-output-not-as-expected-what-am-i-doing-wrong/#findComment-1142130 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.