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

132
Views
New date function is not returning future date as expected

I need Date in IST format so here I am trying to pass the date into three formats, first format gives the correct result but I need the second and third format where the year is passed in the last two digits but if the digits are less then 50 it's giving correct result if it is more then 50 it's giving 1950 as year, in my code I need it to pass as two digits only.

Basically, I need the date format as dd-mm-yy or dd/mm/yy

console.log(new Date(
  `04/1/2050`
))// correct
console.log(new Date(
  `04/1/50`
))// false
  console.log(new Date(
    `04/1/40`
  ))// correct

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

0

Following are the rules from ECMA (https://262.ecma-international.org/11.0/#sec-date-constructor)

If 0 ≤ yi ≤ 99, let yr be 1900 + yi; otherwise, let yr be y.

So this

console.log(new Date(
    `04/1/40`
  ))

// 1940-03-31

I guess Browser's are taking liberty in this rule. And changed this rule to something like

If 0 ≤ yi ≤ 49, let yr be 2000 + yi

You can use same logic in your code too. But make sure it is implemented same way in every browser.

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!