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

Link to comment
Share on other sites

 

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.