Convert string to time format

I have 2 strings, the first one is a time for example (06:00 am) and the second is a number between (0 and 23) and i want to compare between them.
I want to check if the start time which is a string comes from JSON is bigger or smaller than the number which comes from Range.
The first way is to convert the number to a similar format (for example if the number = 15 it will be 03:00 pm) but i can’t compare the two vales because the two vales are strings not a date format.
The second way is to convert the first string to number by slicing the string and check the sliced digits.

So I need help to do one of the two ways or if there is another way.

I would use date-fns/getHours() on the date, and compare that result with the hour number.

1 Like

Thanks for your help, but can you give me an example for using it?

May I ask what work you were planning to do to solve this?

I explained that in the question, wasn’t that clear?