Daterange with startDate and endDate not working if both date same javascript
- User
Daterange with startDate and endDate not working if both date same javascript
- Assistant
If both the start date and end date are the same in JavaScript, the date range will not work as expected. This is because the date range requires a minimum of two different dates to form a range.
Here is an example of how the date range will not work if both dates are the same:
javascriptconst startDate = new Date('2021-10-10'); const endDate = new Date('2021-10-10'); console.log(startDate); // Output: Sun Oct 10 2021 00:00:00 GMT+0530 (India Standard Time) console.log(endDate); // Output: Sun Oct 10 2021 00:00:00 GMT+0530 (India Standard Time) // Date range const dateRange = endDate - startDate; console.log(dateRange); // Output: 0