Skip to content
Advertisement

Checking if time falls between two times using moment not working correctly

I am trying to check if a time occurs between two times 4:29 PM and 8:59AM using moment.js, however it doesn’t work, here is my code:

JavaScript

However it does work if I change 8:59AM to 9:00 PM, it just doesn’t work if I go into the AM, can anyone help me fix this?

EDIT 3: I just got it working, but this code seems a little much, I would appreciate it if anyone has a better way of doing this:

JavaScript

Advertisement

Answer

The moment parser is picky I guess. This format works, plus you were missing some var declarations on the time variables and missing some semicolons at the end of lines:

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