Android Question finding out if DateTime.Now time is between a start time and and ending time

Status
Not open for further replies.

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

I would like to know if anyone has written a function that tests wether a given time in ticks is between a starting time.

For example:

Starting time would be today at 10pm.
Ending time would be tomorrow at 1:30am.

So I would like to test if the current time is between the above times. 1:05am would return True in this scenario.

Thanks.
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Well shouldnt be to difficult.

B4X:
sub timesComparative (starttime as long, endtime as long, betweentime as long) as boolean
if starttime <= betweentime and betweentime <= endtime then
return true
else
return false
end if
end sub

Yep,
 
Upvote 0

Paperinik

Member
Licensed User
Longtime User
Ok, I know that...probably I forgot to tell that this routine is checked in a timed cycle and the date calculated is always current date...

In your case you have to include the date
Can you write a simple example to show what do you mean?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Can you write a simple example to show what do you mean?
Here is an example to calculate time between 2 times. This works even if the days are different
B4X:
DateTime.DateFormat = "yyyy-MM-dd HH:mm:ss"  'chamge date format to your preference
    Dim p As Period =DateUtils.PeriodBetween(DateTime.DateParse( "2020-12-20 20:10:13" ), DateTime.DateParse( "2020-12-20 22:14:50" ))
    Log($"${p.Hours}:${p.Minutes}:${p.Seconds}"$) 'displays: 2:4:37
    Log($"$2.0{p.Hours}:$2.0{p.Minutes}:$2.0{p.Seconds}"$)  'displays: 02:04:37
Need Datetutils library checked
 
Upvote 0
Status
Not open for further replies.
Top