time difference between two time stamps

sangee

Member
Licensed User
[RESOLVED] time difference between two time stamps

Hi,

Can any one help in finding the time difference in minutes between two time stamps please...

My time stamp looks like

"2012-11-08 11-10-00" - which is YYYY-MM-DD HH-MM-SS

if i have a new time stamp for example 2012-11-08 11-20-00

If i can get the difference between the old and new time stamp would be 5 minutes.

diffmins = oldtimestamp - newtimestap

Thanks in advance...

Regards,
Sangee
 
Last edited:

derez

Expert
Licensed User
Translate the date-time strings to Ticks, using DateTimeParse.
Subtract old from new and divide by TicksPerMinute.
 
Upvote 0

sangee

Member
Licensed User
Hello Derez,

Can you please let me know with the code example please considering i am a :sign0104:

Meanwhile.. I will try out too..

Thanks,
Sangee

Got this in a search .. searched using the string DateTimeParse.. Erel's Code..

This should work for me isnt it?

B4X:
Sub DateBetweenTwoDates(D1 As String, T1 As String, D2 As String, T2 As String)
    Dim start, endTime, t As Long
    start = DateTime.DateTimeParse(D1, T1)
    endTime = DateTime.DateTimeParse(D2, T2)
    Dim days, hours, minutes, seconds As Int
    t = Abs(endTime - start)
    days = Floor(t / DateTime.TicksPerDay)
    hours = Floor((t Mod DateTime.TicksPerDay) / DateTime.TicksPerHour)
    minutes = Floor((t Mod DateTime.TicksPerHour) / DateTime.TicksPerMinute)
    seconds = Floor((t Mod DateTime.TicksPerMinute) / DateTime.TicksPerSecond)
    
    Log("Days = " & days)
    Log("Hours = " & hours)
    Log("Minutes = " & minutes)
    Log("Seconds = " & seconds)
    Msgbox("Days = " & days & CRLF & "Hours = " & hours & CRLF & "Minutes = " & minutes & CRLF & "Seconds = " & seconds, "OK")
    
End Sub
 
Last edited:
Upvote 0

sangee

Member
Licensed User
Thank Erel..and Derez.... this worked...

B4X:
Public Sub CheckUptime()
difMin =  MinutesBetweenTimes(Strvalue,CurStr)
ToastMessageShow("Uptime is " & difMin & " Min !!!",True)
End Sub

Sub MinutesBetweenTimes( Time1 As String, Time2 As String)
    Dim start1, start2, t As Long
    start1 = DateTime.TimeParse(Time1)
   start2 = DateTime.TimeParse(Time2)
   Return Floor((start2 - start1) / DateTime.TicksPerMinute)
End Sub
 
Upvote 0

anaylor01

Well-Known Member
Licensed User
So the user selects a time. Let's say 11:30pm. Which in code would be 2300. What is the format I have to have to make it work? If someone could give me a quick example code that would be appreciated. DateUtils.PeriodBetween
 
Upvote 0

anaylor01

Well-Known Member
Licensed User
There are 2 different timedialog boxes. The time difference will be between the two times they selected. So it won't have anything to do with NOW or timeticks.
 
Upvote 0
Top