Skip to content
Advertisement

Check times span over two days as well as within the same day using momentjs

Given the following two times without dates and using moment, how can I best check the following two scenarios based on 24 hours times:

1)

JavaScript

Using the startTime I need to set some flag (boolean) indicating that the endTime has spanned over to the next day and not within the same 24 hour period of the startTime?

2)

JavaScript

the same as item (1) but this time setting a flag indicating that the startTime and endTime are within the same 24 hour period

Advertisement

Answer

Here’s a snippet. Took the liberty to replace let by const, as there are no expected modifications to the variables.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement