I would say the simplest way would be to change the colon to a period, converting to a long (b4a converts string to long for you)
B4X:
Dim strStartTime As String
Dim strEndTime As String
Dim lngStartTime As Long
Dim lngStartTime As Long
strStartTime = "17:45"
strEndTime = "19:00"
lngStartTime = strStartTime.Replace(":",".")
lngEndTime = strEndTime.Replace(":",".")
Another way is to convert the Time to Long (ticks) and then do a compare.
B4X:
DateTime.TimeFormat="HH:mm"
Dim StartTimeTicks As Long
StartTimeTicks = DateTime.TimeParse(StartTime)
Dim EndTimeTicks As Long
EndTimeTicks = DateTime.TimeParse(EndTime)
If EndTimeTicks < StartTimeTicks Then
'Do something
End If
Even easier is just compare the two strings! Presumable the EndTime of 0 indicates an empty value which ought to be set by the program say as "0", or any other value which precedes "00:00".
Then:
B4X:
If EndTime.CompareTo( "0" ) > 0 and EndTime.CompareTo( StartTime ) < 0 Then
'End time set and endtime before start time!
'stop right there
End If
Don't know what the application is, but what happens if start is before midnight and stop is after midnight - If that is a possibility then the 'ticks' solution might be best; although a date&time string in the form of 'YYYYMMDDhhmmss' would work, and has the advantage of being human readable.
The "ticks" solution will not work for me because the times I am comparing are all relative to the same day - meaning starting at midnight. Thus 11:00PM would be less than 1:00AM, 2 hours later.
I think Admac231's solution will work best - replacing ":" with "."
The ticks solution will work because when you time parse in B4A it uses the current date to calculate the ticks to give a meaningful ticks from epoch, otherwise it would only be giving ticks from midnight. So any time parse done on the same day will always give ticks/times relative to each other thus 1:00am < 11:00pm.