0

I have 2 dates to compare in Javascript i.e. "2019-05-26" and "26-05-2019". What will be the best approach to achieve the same?

I tried below and gives me true value, but not sure if that is the right way to do it.

Date("26-05-2019") === Date("2019-05-26");

Thanks.

Shantanu Tomar
  • 1,572
  • 7
  • 38
  • 64
  • *"but not sure if that is the right way to do it"* No, not reliably cross-browser. See the linked question's answers for what to do instead. – T.J. Crowder May 26 '19 at 12:43
  • 2
    `"26-05-2019".split('-').reverse().join('-') === "2019-05-26"`. In this case, you don't need to have two `Date` objects. – mattemyo May 26 '19 at 12:44

0 Answers0