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."; } Quote Link to comment 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! Quote Link to comment 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."; } Quote Link to comment 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.