Welcome to Geeklog Monday, October 23 2017 @ 10:10 pm EDT


Jeremy1701

Anonymous
Haven't seen a count down block either, but I needed one, so here it is.

/* Jeremy's countdown timer */
function phpblock_countdown() {

// enter start date below like this: "January 2, 2001"
$end = "May 13, 2006";

// enter string of what this start date is.
$text = " until our wedding!!";
$textOnTheDay = "Today is the<br />wedding day!!!";
$textAfterwards = "We're married!!!";

//-

$retval .= ' ';

$now = strtotime ("now&quotWink;
$then = strtotime ("$end&quotWink;
$difference = $then - $now;
$num = $difference/86400;
$days = intval($num);
$num2 = ($num - $days)*24;
$hours = intval($num2);
$num3 = ($num2 - $hours)*60;
$mins = intval($num3);
$num4 = ($num3 - $mins)*60;
$secs = intval($num4);
if ($days>0 || $hours>0 || $minutes>0 || $seconds>0) {
$retval = $days .' days<br />' . $hours . ' hours<br />' . $mins . ' minutes<br>' . $secs . ' seconds<br />' . $text;
}
else if (($days==0) && ($hours<=0 || $minutes<=0 || $seconds<=0)) {
$retval .= $textOnTheDay;
}
else {
$retval .= $textAfterwards;
}

return $retval;
}

Shan

Anonymous
happy
That is exactly what I was looking for AND it works great! Thanks jeremy1701!



Shan

Status: offline

machinari

Forum User
Full Member
Registered: 22/03/2004
Posts: 1512
here is an easy on that I have used here and there...
PHP Formatted Code
function phpblock_countdown(){
  // Change the Dates to meet your needs
  $day = 23; // Day of the countdown
  $month = 8; // Month of the countdown
  $year = 2004; // Year of the countdown

  $retval = ('There are ' . (int)((mktime (0,0,0,$month,$day,$year) - time(void))/86400)
    . ' days left \'til the <i>insert event here</i> goes online');

  return $retval;
}

 

Status: offline

1000ideen

Forum User
Full Member
Registered: 04/08/2003
Posts: 1289
Good ideas! machinari could you extend that to hours, minutes and seconds as well? Sound like a silly question, but I don`t know php.

It would also be nice if another message would be displayed if the countdown is done, e.g. "The show is on now!"

Aaaand another problem, how could a user input the time online? Hm, maybe a stupid idea, but could I write a story with a specific ID like "countdown" in which I only type:

$seconds = 00; // second of the countdown
$minutes = 59; // minutes of the countdown
$hours = 12; // hours of the countdown
$day = 23; // Day of the countdown
$month = 8; // Month of the countdown
$year = 2004; // Year of the countdown

And maybe the additional features of Jeremy:
$text // what event
$textOnTheDay // text on the hour of event
$textAfterwards // text after the event

Status: offline

machinari

Forum User
Full Member
Registered: 22/03/2004
Posts: 1512
PHP Formatted Code

$timeLeft = ((int)(mktime ($hour,$minute,$second,$month,$day,$year) - time(void));
if ($timeLeft <= 0) {
    $retval = 'The <i>insert event here</i> is now playing!';
} else {
    $retval = 'There are ' . $timeLeft . ' seconds left until the <i>insert event here</i> goes online');
}
return $retval;

 
with a bit of math you can change $timeLeft into years, months, days, etc.
Hope that helps. I didn't test it so I dunno if it works. You can find all kinds of scripts like this around the net.

Status: offline

machinari

Forum User
Full Member
Registered: 22/03/2004
Posts: 1512
oh, and if you wanted to enter the time into a web form, you could store the event date in the database and just run a query for the date from within this function.
easy as pie!

Status: offline

1000ideen

Forum User
Full Member
Registered: 04/08/2003
Posts: 1289
Thanks, you are so right with "You are limited only by your imagination..."

After writing this I got one more idea. What I hope someone to develope is a podcast plugin and if it is for GL then it should be one that is 3 times better than any other.

So I have 2 things in mind. The one is this countdown and the other thing is a teaser box telling you intelligent random things like "did you know about ...?"
http://www.geeklog.net/forum/viewtopic.php?forum=9&showtopic=63254


I put some more ideas into the countdown timer:


PHP Formatted Code
function phpblock_podcastcountdown() {

global $LANG01, $LANG_WHATSNEW;

// find stories in topic e.g. "podcast" with future date, compare if this date is in the future or present time plus 1 hour.
Iif there are more than 1 stories choose the next story, if there is no story then don't activate block

//end of countdown = story_date
$countdown_end = {story_date};

// countdown event = story_title
$countdown_event = till the next podcast: {story_title};

$text_on_countdown_event = The podcast is on!

$retval .= '
';

$now = strtotime ("now");
$then = strtotime ("$countdown_end");
$difference = $then - $now;
$num = $difference/86400;
$days = intval($num);
$num2 = ($num - $days)*24;
$hours = intval($num2);
$num3 = ($num2 - $hours)*60;
$mins = intval($num3);
$num4 = ($num3 - $mins)*60;
$secs = intval($num4);
if ($days>0 || $hours>0 || $minutes>0 || $seconds>0) {
$retval = $days . $LANG_WHATSNEW[days]'
' . $hours .  $LANG_WHATSNEW[hours]' ' . $mins . $LANG_WHATSNEW[minutes]'  <br>' . $secs . $LANG01[92]' ' . $countdown_event;
}
else if (($days==0) && ($hours==0 || $minutes<=0 || $seconds<=0)) {
$retval .= $text_on_countdown_event;
}
else {
//deactivate block!
}

return $retval;
}
?>


Uh, this is code gibberish but you get the idea? One should not have to creep into the lib-custom every time to change anything and it should be international.


===========
I`m sorry but my knowledge is more on ideas and concepts rather than detailed programming...

Indeed you find scripts on the net. The above "Jeremy's countdown timer " turned out to be by Jennifer the scriptygoddess. http://www.scriptygoddess.com/archives/2002/05/23/count-up-timer-in-php/

Status: offline

ofey

Forum User
Full Member
Registered: 18/03/2005
Posts: 213
Location:Dublin, Ireland
thoughtful
Rather than the countdown just be accurate at the time of loading the page is it possible that the countdown timer, actually counts down as you look at it in real time. In other words is there some way to actually constantly refresh it?

Shane
Those who say it can't be done, are usually interrupted by others doing it.

Wal

Anonymous
cheerful
Quote by: ofey

Rather than the countdown just be accurate at the time of loading the page is it possible that the countdown timer, actually counts down as you look at it in real time. In other words is there some way to actually constantly refresh it?

Shane



Not sure if you found a solution to this but this is what I use.

PHP Formatted Code
<script language="JavaScript1.2">
function setcountdown(theyear,themonth,theday,thehour,themin,thesec){
yr=theyear;mo=themonth;da=theday;hr=thehour;min=themin;sec=thesec
}

//////////CONFIGURE THE COUNTDOWN SCRIPT HERE//////////////////

//STEP 1: Configure the countdown-to date, in the format year, month, day, hour(0=midnight,23=11pm), minutes, seconds:
setcountdown(2007,11,24,00,00,00)

//STEP 2: Change the two text below to reflect the occasion, and message to display on that occasion, respectively
var occasion=""
var message_on_occasion="Election Dayt"

//STEP 3: Configure the below 5 variables to set the width, height, background color, and text style of the countdown area
var countdownwidth='140px'
var countdownheight='90px'
var countdownbgcolor='clear'
var opentags='<font face="Verdana"><mediuml></font><font color="blue">'
var closetags='</medium></font>'

//////////DO NOT EDIT PAST THIS LINE//////////////////

var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var crosscount=''

function start_countdown(){
if (document.layers)
document.countdownnsmain.visibility="show"
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all?document.getElementById("countdownie") : countdownie
countdown()
}

if (document.all||document.getElementById)
document.write('<span id="countdownie" style="width:'+countdownwidth+'; background-color:'+countdownbgcolor+'"></span>')

window.onload=start_countdown


function countdown(){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[mo-1]+" "+da+", "+yr+" "+hr+":"+min+":"+sec
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
//if on day of occasion
if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=1&&todayd==da){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+message_on_occasion+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+message_on_occasion+closetags
return
}
//if passed day of occasion
else if (dday<=-1){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+"Occasion already passed! "+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+"Occasion already passed! "+closetags
return
}
//else, if not yet
else{
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds "+occasion+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds "+occasion+closetags
}
setTimeout("countdown()",1000)
}
</script>

<ilayer id="countdownnsmain" width=&; height=&; bgColor=&; visibility=hide><layer id="countdownnssub" width=&; height=&; left=0 top=0></layer></ilayer>

</body>


You can see it working here - http://www.noexceptionfees.com


Status: offline

ofey

Forum User
Full Member
Registered: 18/03/2005
Posts: 213
Location:Dublin, Ireland
happy
Thanks Wal for the code. But how would you change the code to count only in second or only in days a or whatever?

Shane

Those who say it can't be done, are usually interrupted by others doing it.

Wal

Anonymous
stressed
Quote by: ofey

Thanks Wal for the code. But how would you change the code to count only in second or only in days a or whatever?

Shane



Hey Shane

Up the top in the three sections I have coded a way of setting the count down to work, if you want to show only the days you will have to modify the body of the script.

I would do it for you but I am very busy and on a huge deadline for a project due next week.

Sorry

Wal

Status: offline

ofey

Forum User
Full Member
Registered: 18/03/2005
Posts: 213
Location:Dublin, Ireland
happy
Wal,

No problem. I'll play around with the code anyway.

Thanks for the code you have put up, it's a great help.

Shane
Those who say it can't be done, are usually interrupted by others doing it.

All times are EDT. The time is now 10:10 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content