0

I am trying to collect a date from text boxes and then do a comparison on them. I am entering the dates in dd-MM-yyyy format, however when the comparison is running its running is in a MM-dd-yyyy format.

my fiddle is here

in my live application I am using a bootstrap datepicker to enter the date so the date entered will always be the correct format.

Ive looked here at W3 Schools and I have also tried looking at

var dt1  = d1.split(/\-|\s/)
var dt2  = d2.split(/\-|\s/)
dat1 = new Date(dt1);
dat2 = new Date(dt2);
dat1.format("dd-MM-yyyy")

but this also fails.

Any and all help very much appreciated.

thanks

2
  • The Date constructor does not accept arrays as parameter! Commented Oct 28, 2015 at 10:23
  • I mean, it'll just cast it to string in the first place. Commented Oct 28, 2015 at 10:25

1 Answer 1

1

Use the getTime() method if you want to make comparison on dates :

if(dat1.getTime() > dat2.getTime()) { ... }

On your example : https://jsfiddle.net/3ut8a7zj/1/

Sign up to request clarification or add additional context in comments.

1 Comment

Although its not in the format I am looking for it still works thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.