1

I have an application that works in several "cultures". I will be using many date formats.

I have a string with my format (i.e. 'd/m/y', but keep in mind this is variable) and 2 text inputs with dates in that given format.

I need to compare the dates in input box 1 to input box 2. I had a method that did this fine, until we added the international formatting.

new Date(endDate) >= new Date(startDate)

This used to work with U.S. only dates. It does not now. Is there a method I can use that works like this?:

new Date(endDate, 'd/m/y')
Neil M.
  • 456
  • 5
  • 16

1 Answers1

1

You may want to consider moment.js library, which may relieve you from many date manipulation problems, since Javascript can't parse locale formats. For your case, you'd write

moment("12-25-1995", "MM-DD-YYYY");

which would create a "moment" object, parsing date string to the provided template.

punund
  • 4,321
  • 3
  • 34
  • 45