Android Question Time difference

Declan

Well-Known Member
Licensed User
Longtime User
I have two times in String format:
B4X:
Start Time: ($"$2.0{0}:$2.0{MyTime}:$2.0{0}"$) ------> 00:04:00
End Time: ($"$2.0{hours}:$2.0{minutes}:$2.0{seconds}"$) ------> 00:03:31

How can I get the difference: (Start Time) - (End Time)
I can do this with DateDiff, but how can I convert the strings into ticks (DateTime) format?
 

DonManfred

Expert
Licensed User
Longtime User
create a long (datetime) with the current day and the time (ParseDatetime) for both values (starttime, endtime)

You then can use
B4X:
dim p as period = dateutils.PeriodBetween(starttime, endtime)
log(p)
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
@DM
I am not attempting to waste your time.
What I meant by:
Sorry, I don't understand.
is simply:
Instead of converting the two time Strings to Ticks, should I create two separate Long variables?
One being the starttime and one the endtime?
I have used DateUtils.PeriodBetween with success in the past, but never have I attempted to convert a String to Ticks.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I have used DateUtils.PeriodBetween with success in the past, but never have I attempted to convert a String to Ticks.

Is this what you are after:
B4X:
Dim MyTime As Int =4
    Dim Starttime, Endtime As String
    Endtime =$"$2.0{0}:$2.0{MyTime}:$2.0{0}"$   '00:04:00
    Dim hours=0 As Int, minutes=3 As Int, seconds =31 As Int 
    Starttime = $"$2.0{hours}:$2.0{minutes}:$2.0{seconds}"$   '00:03:31
    Dim CurDate As String =DateTime.Date(DateTime.Now)
    Dim p As Period = DateUtils.PeriodBetween(DateTime.DateTimeParse(CurDate,Starttime), _
    DateTime.DateTimeParse(CurDate,Endtime) )
    Log($"${p.Hours} hrs ${p.Minutes} min ${p.Seconds} sec"$ )   'displays: 0 hrs 0 min 29 sec
 
Upvote 0
Top