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

84
Views
MomentJS isAfter returning incorrect data

I want to know if a date (2021-11-09) is after another date (2021-11-11) in YYYY-MM-DD format, which should be false, right ?

  console.log(
    moment("2021-11-09", "YYYY-MM-DD", true).isAfter(
      "2011-11-11",
      "YYYY-MM-DD",
      true
    )
  );

but, above code return true.

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

0

the doc of momentjs states:

If you want to limit the granularity to a unit other than milliseconds, pass the units as the second parameter.

As the second parameter determines the precision, and not just a single value to check, using day will check for year, month and day

So you should use a unit instead of format string though it seems the result is same.

console.log(
  moment("2021-11-09", "YYYY-MM-DD", true).isAfter(
    "2011-11-11",
    "day" //"YYYY-MM-DD"
  )
)
console.log(
  moment("2021-11-09", "YYYY-MM-DD", true).isAfter(
    "2021-11-11",
    "day" //"YYYY-MM-DD"
  )
)
<script src="https://unpkg.com/moment@2.29.1/moment.js"></script>

about 4 years ago · Juan Pablo Isaza Report

0

The dates you're comparing in code and the ones in your questions are not aligned. And code is returning true correctly. Because 2021-11-09 is indeed after 2011-11-11

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!