Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need a Repeating Countdown timer

    Hi guys.

    I'm making a website and for couples of days I have been trying to create a simple repeating countdown, but because I don't have that experience in HTML I could not do it
    I want a code that countdown from 30 days until 0 , and as soon as it counts down, I need it to reset to 30 days again. I need only the numbers without "days".

    Thanks guys, your help is highly appreciated.

    Regards

  • #2
    New Coder
    Join Date
    Jun 2014
    Location
    Minnesota
    Posts
    31
    Thanks
    4
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by Sultan53 View Post
    Hi guys.

    I'm making a website and for couples of days I have been trying to create a simple repeating countdown, but because I don't have that experience in HTML I could not do it
    I want a code that countdown from 30 days until 0 , and as soon as it counts down, I need it to reset to 30 days again. I need only the numbers without "days".

    Thanks guys, your help is highly appreciated.

    Regards
    Something like this? Edit fiddle - JSFiddle

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Quote Originally Posted by Sultan53 View Post
    Hi guys.

    I want a code that countdown from 30 days until 0 , and as soon as it counts down, I need it to reset to 30 days again. I need only the numbers without "days".

    When is the 30 days to start? From a fixed date/time? From when the user first logs on to your site? Or what? Please be more explicit. Be aware that a user can delete cookies. You want just days - not days/hours/minutes?
    Last edited by Philip M; 06-27-2014 at 11:42 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #4
    New to the CF scene
    Join Date
    Jun 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    When is the 30 days to start? From a fixed date/time? From when the user first logs on to your site? Or what? Please be more explicit. Be aware that a user can delete cookies. You want just days - not days/hours/minutes?
    If I can start it from specific date that will be great, however it's gonna repeat itself every 30 days forever. I just want the number of days without hours or minutes.

    Thank you so much.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Quote Originally Posted by Sultan53 View Post
    If I can start it from specific date that will be great, however it's gonna repeat itself every 30 days forever. I just want the number of days without hours or minutes.

    Thank you so much.
    Try this:-

    Code:
    <script type = "text/javascript">
    
    var one_day = 1000*60*60*24;   // milliseconds in one day
    var x = new Date(2014,5,1);  // arbitary start date 1st June 2014  Months in Javascript are 0-11
    var y = new Date();  // today
    var diff = (y.getTime() - x.getTime()) / one_day;    // difference in days between the two dates
    diff = (Math.floor(diff))%30;   // whole number 0-29
    diff = 30-diff;  // 30-1
    alert (diff);
    
    </script>

    Obviously you can change the starting date to suit your requirements.
    I have to say that I do not really see the point.


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 06-28-2014 at 07:48 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •