Tubiss
July 16, 2019, 9:01am
1
private eventDate: Date = new Date('July 16, 2019 12:24:00');//this is another date
private today : Date=new Date();
if(this.today==this.eventDate{
console.log(hello)
}
its not working as this like but when ı make below hello is displayed
if(this.today!=this.evetDate){
console.log(hello)
}
ı mean private today : Date=new Date();
that is not getting today date please help me how can ı get current date
Hi Tubiss,
You shouldn’t compare two objects with “==” / “!=” operator.
If you want to check if this two dates are the same you can use
if (this.today.getTime() === this.eventDate.getTime()) {}
You can also check if its the same day etc.
See more here
I use and recommend date-fns for all tasks like this.
var day = new Date();
Tue Jul 16 2019 15:11:12 GMT-0400
if you only want to compare date
you can use day.substr()
to get what you want from this string