I want to compare two dates using this code
let dob=new Date(this.dob);
if(birthDate.getDate()==new Date("1990-01-01").getDate())
{
console.log('date is equal');
}
else
{
console.log('date is not equal');
}
but it shows date is equal when i have 2022-08-01
this date in birthDate
variable.
Any solution Thanks
CodePudding user response:
The getDate
method of Date
returns the day of the date (in both cases you gave as an exampel, this is 01
). To compare between dates, you can use the getTime
method (returns the number of milliseconds passed since Jan 1st, 1970)
CodePudding user response:
you can use momentjs like this
var bool2 = moment('2019-10-20').isSame('2019-10-20'); //true
console.log(bool2);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script>