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

172
Views
How to convert Number to Date Using date-fns

I m trying to convert number into Date using date-fns.

Current : 20220211 or '20220211' (May be number or string)

Expected : Fri 11Feb

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

0

date-fns takes Date as an argument. First you should convert your string date value to a valid Date instance. Date could take several types of value, including ISO 8601 date standard, which means you could pass 2022-02-22 string value to Date constructor and it will be valid.

If your string format is not going to change your could do this:

const dateStr = '20220211';
const year = dateStr.slice(0,4);
const month = dateStr.slice(4,6);
const day = dateStr.slice(6,8);
const date = new Date(`${year}-${month}-${day}`);

And then use date in 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!