Jump to content

Subtract time()-14 from time() output not as expected. What am I doing wrong?


OldWest

Recommended Posts

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.";
}

 

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.";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.