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 returning unexpected result

Unsure what I am doing wrong with my dates together with moment.js.

I have the following code:

function(value) {                        
  const startDate = moment(this.parent.startDate).format("DD/MM/YYYY")
  const endDate = moment(value).format("DD/MM/YYYY")
  console.log("SE",startDate,endDate)
  return moment(startDate).isSameOrBefore(moment(endDate))
}

The output of my console.log for both startDate and endDate is:

SE 15/08/2021 19/08/2021

For some reason though, when calling this function, it is saying that my:

End date must be greater than or equal to start date

which based on my return moment(startDate).isSameOrBefore(moment(endDate)), should not be the case as end date 19/08/2021 is after start date 15/08/2021

What am I missing?

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

0

Compare the original dates, not the formatted dates, since moment.js doesn't know that they're in DD/MM/YYYY format.

function(value) {                        
  const startDate = moment(this.parent.startDate).format("DD/MM/YYYY")
  const endDate = moment(value).format("DD/MM/YYYY")
  console.log("SE",startDate,endDate)
  return moment(this.parent.startDate).isSameOrBefore(moment(value))
}
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!