Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
How to convert jquery countdown function to countup function?

I am working on a portal which is basically using a jquery plugin called countdown i.e. https://github.com/hilios/jQuery.countdown

The piece of code is:

$(document).ready(function(){

$("#countdown").countdown("2022/06/25 10:00:00", function(event) {
  var $this = $(this).html(event.strftime(''
     + '%-D Days'
});

How can I make it in reverse? Instead of counting it down to the date, is it possible to count from the date? and display how many days it's been.

Any help would be highly appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As you have not posted the complete countdown function, I am assuming the one from the link you have pasted (https://github.com/hilios/jQuery.countdown)

If you carefully look at the countdown function here https://github.com/hilios/jQuery.countdown/blob/223789964fd1854e04a60d6eba3fd22d20b1f34f/src/countdown.js#L269 you can easily modify it.

I have had similar requirements in the past and writing my own function was easier than modifying the existing one.

For example, the function:

$(document).ready(function () {
    $(function () {
      var calcNewYear = setInterval(function () {
        var date_started = new Date("2022/06/25"); // your date to count from
        var date_now = new Date(); // current timestamp 
        var one_day = 1000 * 60 * 60 * 24;
        var days = Math.floor((date_now - (date_started)) / one_day); // days from the date
        }
    }
}

Then include it wherever it is needed:

("#countdown").html(days + ' Days');
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!