Hi everyone. Im developing a medical system and I need from Given a range of hours e.g. 12pm 06pm fragment in 15 minutes e.g. 12pm 12:15 12:30 12:45 etcetera. I don't know how to start. I don't know if to use dateutils library or just strings. Thanks
Without a question mark in your post, it is difficult to identify the question. Are you asking which format/type you should use to store dates and times?
Usually I would say to use the DateUtils library, but it sounds more here like you are generating a list of undated times to construct a fixed-format form or table or document. If you are operating overnight, then you would need to consider what happens when summer time / daylight saving kicks in or out.
An implementation that meets your example need (and more) is:
B4X:
'times are in minutes since midnight eg 4:56 pm = (12 + 4) * 60 + 56
Dim OpenTimeMinutes As Int = 12 * 60 '12 midday
Dim CloseTimeMinutes As Int = 18 * 60 '6 pm
Log( "Afternoon sessions are " & SessionTimes(OpenTimeMinutes, CloseTimeMinutes, 15) )
OpenTimeMinutes = 22 * 60 + 30 '10:30 pm
CloseTimeMinutes = (24 + 5) * 60 + 20 '5:20 am next day
Log( "Overnight sessions are " & SessionTimes(OpenTimeMinutes, CloseTimeMinutes, 15) ) 'note there is NO session at 05:15 due to closing 5 minutes later
Sub SessionTimes(StartMinutes As Int, EndMinutes As Int, SessionMinutes As Int) As List
Dim SessionList As List
SessionList.Initialize
If SessionMinutes > 0 Then
For T = StartMinutes To EndMinutes - SessionMinutes + 1 Step SessionMinutes
SessionList.Add( NumberFormat2(Floor(T / 60) Mod 24, 2, 0, 0, False) & ":" & NumberFormat2(T Mod 60, 2, 0, 0, False) )
Next
End If
Return SessionList
End Sub
Or this... (background info for people not abreast with Australian politics: Julia Gillard was our first female Prime Minister, but before that she was Deputy PM to Kevin Rudd, who had a reputation for driving people hard... freaky thing about this clip is that it was done *before* Kevin got dumped):
B4X:
'♪♫ working nine to nine ♫♬...
Dim SessionList As List = Array As String( _
"09:00", "09:15", "09:30", "09:45", _
"10:00", "10:15", "10:30", "10:45", _
"11:00", "11:15", "11:30", "11:45", _
"12:00", "12:15", "12:30", "12:45", _
"13:00", "13:15", "13:30", "13:45", _
"14:00", "14:15", "14:30", "14:45", _
"15:00", "15:15", "15:30", "15:45", _
"16:00", "16:15", "16:30", "16:45", _
"17:00", "17:15", "17:30", "17:45", _
"18:00", "18:15", "18:30", "18:45", _
"19:00", "19:15", "19:30", "19:45", _
"20:00", "20:15", "20:30", "20:45" _
)
Log(SessionList)