0

I have a countdown at my site, i want it to countdown to next Friday, and when the friday is over, i want it to automatically countdown to the next Friday.. and just repeat that..

I have this script, but cant seem to get it to work, can some one help me here ?

Thanks in advance

$(function(){

var note = $('#note'),
    ts = new Date(5), //Setting the date here
    newYear = true;

if((new Date()) > ts){
    ts = (new Date()).getTime() + 10*24*60*60*1000;
    newYear = false;
}

$('#countdown').countdown({
    timestamp   : ts,
    callback    : function(days, hours, minutes, seconds){

        var message = "";

        message += days + " day" + ( days==1 ? '':'s' ) + ", ";
        message += hours + " hour" + ( hours==1 ? '':'s' ) + ", ";
        message += minutes + " minute" + ( minutes==1 ? '':'s' ) + " and ";
        message += seconds + " second" + ( seconds==1 ? '':'s' ) + " <br />";

        if(newYear){
            message += "left until the new year!";
        }
        else {
            message += "left to 10 days from now!";
        }

        note.html(message);
    }
});

});
Patrick R
  • 1,949
  • 3
  • 32
  • 58

1 Answers1

2

Use the getDay() method that exist on the Date object which will return the number of the day 0 = Sunday, 1 = Monday, 5 = Friday.
Determine which day it is today and how many days it is until the next day number 5.
Then ts = (new Date()).getTime() + 60*60*24*daysUntilFriday*1000;
After this you also want to use the method setHours(), setMinutes(), and Seconds to 0 so that you get the exact time until Friday starts.

EDIT! Sorry when you are done with your ts variable you want to use setTime(ts) so that you get a new Date object with the next Fridays date. And then you start setting hours, minutes and seconds to zero and then getTime() again so that your ts is the correct format for your countdown method.

Good luck!

Regards Tobias

Seybsen
  • 14,989
  • 4
  • 40
  • 73
Tobias
  • 873
  • 9
  • 17
  • Here you can read more about the Date object http://www.w3schools.com/jsref/jsref_obj_date.asp – Tobias Aug 22 '12 at 14:18
  • Thanks for the feedback. Is it possible you can explain where i the code i shall do what ? im not into JS that much. I found this script – Patrick R Aug 23 '12 at 14:51
  • The getDay() method returns the day of the week (from 0 to 6) for the specified date. Note: Sunday is 0, Monday is 1, and so on. – Seybsen Dec 09 '14 at 10:58