1

I have this code using javascript :

var event = new Date('August 19, 1975 23:15:30');
var event1 = new Date('March 25, 1956 15:50:14');

And I would like to know how can I check if the value of event1 is equal to event?

Is there a way I can do this?

Thank you!

rassar
  • 5,412
  • 3
  • 25
  • 41
Pierre
  • 47
  • 3
  • I don't understand what you're asking – j08691 Nov 07 '19 at 15:12
  • 4
    Possible duplicate of [Checking if two Dates have the same date info](https://stackoverflow.com/questions/4428327/checking-if-two-dates-have-the-same-date-info) – leopal Nov 07 '19 at 15:13
  • `.getTime()` will give you milliseconds since 1970 1st January, can you test equate using that ? – Om Sao Nov 07 '19 at 15:14

2 Answers2

3

var event = new Date('August 19, 1975 23:15:30');
var event1 = new Date('August 25, 1956 15:50:14');
var result = CompareDates(event , event1);
console.log(result);

function CompareDates(date1, date2){
  if((date1.getDay() === date2.getDay()) && (date1.getMonth() === date2.getMonth()) && (date1.getYear() === date2.getYear())){
    return "Dates are equal.";
  }
 return "Dates are different.";
}

You can use above simple logic for date comparison.

ankitkanojia
  • 3,072
  • 4
  • 22
  • 35
1

compare the timestamps of the dates:

if(event.getTime() === event1.getTime()){
...
}
CodingKiwi
  • 676
  • 8
  • 22