How to check for two timestamp for the same day?

Given two timestamp then we have to find out whether these time are of same date or not. Here we can use the JavaScript Date Object.

Examples:

  • Input: TimeStamp1 = 20-04-2020 , 16:04:55 and 
           TimeStamp2 = 20-04-2020 , 10:22:42 
    
    Output: These dates are of same date
  • Input: TimeStamp1 = 20-04-2020 , 16:04:55 and 
           TimeStamp2 = 20-04-2019 , 10:22:42
    
    Output: These timestamps are not on the same date.
  • Explanation: These timestamp are of same date i.e. 20-04-2020 In JavaScript Object this date can be convert.
    var D1 = new Date(2020, 04, 20, 16, 04, 55)
    var D2 = new Date(2020, 04, 20, 10, 22, 42)

Approach 1: First Check for year, month and date of both the dates. If all are equal then we can say that these two dates are equal. You check this article JavaScript get Date Methods. To get year we have getFullYear() method, for month we have getMonth() metohd and for date we have getDate() metohd.