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

354
Views
Date-fns: Countdown to a specific date

I'm using date-fns. I need to create a countdown to the next 10th of the month.

For example, if today is 5th Feb, then the countdown should be to 10th Feb. If today is say 15th Feb, then it should count to 10th March, and so on.

How can I do this with date-fns or even with plain javascript?

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

0

You must first find the target date, like this one:

const today = startOfToday();
let target = setDate(today, 10);
if (isBefore(target, today)) {
  target = addMonths(target, 1);
}

Then calculate time remaining until the target:

const diff = differenceInSeconds(target, new Date());
const days = Math.floor(diff / 86400);
const hours = Math.floor((diff - days * 86400) / 3600);
const minutes = Math.floor((diff - days * 86400 - hours * 3600) / 60);
const seconds = diff - days * 86400 - hours * 3600 - minutes * 60;

Use days, hours, minutes, seconds for create a countdown. Don't forget to import required functions from date-fns.

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!