Convert string to time format


#1

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.


#2

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


#3

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


#4

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


#5

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