Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in Web Technology by (47.6k points)

Can someone suggest a way to compare the values of two dates greater than, less than, and not in the past using JavaScript? The values will be coming from text boxes.

1 Answer

0 votes
by (106k points)

If you want to compare two dates with JavaScript then compare them using the >, <, <= or >= operators.

If you want to use the ==, !=, ===, and !== operators then it will require you to use date.getTime() see the code below:-

var d1 = new Date();

var d2 = new Date(d1);

var same = d1.getTime() === d2.getTime();

var notSame = d1.getTime() !== d2.getTime();

Related questions

0 votes
1 answer
asked Jul 15, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
asked Jul 17, 2019 in Python by Sammy (47.6k points)
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
asked Sep 9, 2019 in SQL by Sammy (47.6k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...