gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
check if day is the same in this two dates 2023-07-20T21:30:00.000Z…
- User
check if day is the same in this two dates 2023-07-20T21:30:00.000Z 2023-07-20T23:00:00.000Z javascript
- Assistant
Here's a JavaScript solution to check if the day is the same in the given two dates:
const date1 = new Date('2023-07-20T21:30:00.000Z'); const date2 = new Date('2023-07-20T23:00:00.000Z'); // Get the day of the month for both dates const day1 = date1.getUTCDate(); const day2 = date2.getUTCDate(); // Compare if the day is the same const isSameDay = day1 === day2; console.log(isSameDay); // Output: trueIn this example, we create two
Dateobjects from the given date strings. Then, we extract the day of the month for both dates using thegetUTCDate()method. Finally, we compare if the day of the month is the same and store the result in theisSameDayvariable.