TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 257
  • Total: 257

Countdown Block

Started by Xarcell, November 17, 2005, 04:42:32 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

sburke930

No we do not need a second by second countdown.  Just a simple countdown when a visitor initially comes to the site or each time they refresh would be sufficient.

JPDeni

#21
Okay. This should do what you want.

--code deleted. Look down a couple more posts--

This should give you the days, hours and minutes between the time the page is refreshed and the next Tuesday at 11pm. Between Tuesday at 11pm and Wednesday at 7am it should give a different message -- that "Whatever you want to say..." message. I wasn't able to test that fully, so let me know if it doesn't work like you expect it to.

sburke930

#22
It gives me the "whatever you want to say..." message now.  Oh I am so confused.

NM I fixed it...I had to move the echo statement to the bottom...it works now!

Thank you!

sburke930

Small problem though, it says there are 10 days til next Tuesday....now as far I can remember there are only 7 days of the week...right?  :o ;D

JPDeni

Post the code you're using, please. It looks like you may have changed it.

sburke930

$dayofweek = 'Tuesday';
if (date('l') <> $dayofweek )
{
  $mon = date('n',strtotime('next '.$dayofweek));
  $day = date('j',strtotime('next '.$dayofweek));
  $year = date('Y',strtotime('next '.$dayofweek));
}
else
{
  $mon = date('n');
  $day = date('j');
  $year = date('Y');
}
$target = mktime(23,0,0,$mon,$day,$year);
$difference = $target - time();
if ($difference > 572000 or $difference < 0) 
{
  $days = floor($difference/(24*60*60));
  $difference -= $days * 24 * 60 * 60;
  $hours = floor($difference / (60 * 60));
  $difference -= $hours * 60 * 60;
  $minutes = floor($difference / 60);
  echo $days . ' days ' . $hours . ' hours ' . $minutes . ' minutes left for the current challenge';
}

else

{
  echo 'Whatever you want to say between the closing of one challenge and the beginning of the next';
}


All I did was move the "else" and echo statement to the bottom

JPDeni

Well, moving that code will change everything and make it not work. :) I did have the number wrong, which I'll fix in a second. (Arithmetic was never my strong suit. ;) )

There may be something strange with your system that doesn't know what "next Tuesday" means. It looks like it is making it "a week from next Tuesday."

Try this --


echo '<br />', (date('j',strtotime('next Tuesday'));


Just add it to the bottom of the code. You should get 12 on a line, but I'm thinking you're going to end up with 19. If so, we'll have to subtract a week's worth of seconds from the $difference variable.

sburke930

I am now getting a parse error on line 31.

JPDeni

Try this:

$dayofweek = 'Tuesday';
if (date('l') <> $dayofweek )
{
  $mon = date('n',strtotime('next '.$dayofweek));
  $day = date('j',strtotime('next '.$dayofweek));
  $year = date('Y',strtotime('next '.$dayofweek));
}
else
{
  $mon = date('n');
  $day = date('j');
  $year = date('Y');
}
$target = mktime(23,0,0,$mon,$day,$year);
$difference = $target - time();
if ($difference > 604800)
  $difference -= 604800;
if ($difference > 576000 or $difference < 0) 
{
  echo 'Whatever you want to say between the closing of one challenge and the beginning of the next';
}
else
{
  $days = floor($difference/(24*60*60));
  $difference -= $days * 24 * 60 * 60;
  $hours = floor($difference / (60 * 60));
  $difference -= $hours * 60 * 60;
  $minutes = floor($difference / 60);
  echo $days . ' days ' . $hours . ' hours ' . $minutes . ' minutes left for the current challenge';
}

sburke930

Perfecto!

Thank you, thank you, thank you!

This website is proudly hosted on Crocweb Cloud Website Hosting.