Avatar of DesertWarrior
DesertWarrior asked on

Counter question

Hi guys,

I need a counter that will start by "15 days left" and decrease everyday after midnight (according to the server time which will be Boston, MA)... the site well actually be hosted in Boston offices.

Thanks
PHP

Avatar of undefined
Last Comment
MasonWolf

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
hernst42

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
MasonWolf

Does this need to involve a cron job, or can it simply check itself each time someone observes it?
ASKER
DesertWarrior

no cron jobs..

it must check the time itself and display the proper amount of days remaining...

no matter where the individual is located in the world, as it depends only on the boston servers time...

MasonWolf

hernst42 gave an answer that simply needs you to initialize an end date each time. If that's sufficient then great. If not, can you store a variable in a file? The answer below still requires initializing a start date for your countdown.

<?php
$countdowndays = 15;
$last_updated = strtotime('2007-10-23');
?>

<?php
include('countdown_vars.php');
if($last_updated != strtotime(date('Y-m-d')))
{
     $days = ($last_updated-strtotime(date('Y-m-d'))) / 86400;
     $countdowndays -= $days;
     $file = '<?php'. chr(10).
'$countdowndays = '.$countdowndays';'. chr(10).
$last_updated = strtotime(\''.date('Y-m-d').'\');'. chr(10).
'?>';
     $fp = fopen('countdown_vars.php', 'w');
     fwrite($fp, $file);
     fclode($fp);
}
echo $countdowndays.' days remaining';
?>
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23