0

I've a dateTime string - '2020-04-30 07:00:00'. I need to extract the time '07:00:00' and check if it is less than or equal to '11:30' hrs.

How do I do that in easiest way?

Sunny
  • 902
  • 3
  • 18
  • 41
  • Basically, you need to to the opposite of this: https://stackoverflow.com/questions/25304144/comparing-javascript-dates-while-ignoring-time-of-day – NickB Apr 29 '20 at 09:32

1 Answers1

0

Parse your string to a date:

const d = new Date(Date.parse('2020-04-30 07:00:00'))

Test whatever you want:

if (d.getHours() < 11 || (d.getHours() === 11 && d.getMinutes() <= 30)) {
    // earlier than 11:30 or 11:30
}
Argee
  • 1,216
  • 1
  • 12
  • 22