I am attempting to find the period in minutes between 2 dates.
I was referring to the solution at https://www.b4x.com/android/forum/threads/calculate-difference-between-two-date-strings.39651/ but it does not work for me.
Any help is appreciated.
This is my code
Thanks in advance!
Edit: Changed accuracy from seconds to minutes (it was originally seconds, but after all these problems, if I get diff in minutes, it will do.
I was referring to the solution at https://www.b4x.com/android/forum/threads/calculate-difference-between-two-date-strings.39651/ but it does not work for me.
Any help is appreciated.
This is my code
B4X:
Dim strDateTime1 As String 'DateTime string 201507212215 - yyyyMMddHHmm format
Dim lngDateTime1 As Long
Dim strDateTime2 As String 'DateTime string 201507271355 - yyyyMMddHHmm format
Dim lngDateTime2 As Long
Dim lPeriod As Period
' Calculate the period (in minutes) between 2 dates
' My realtime app will have a diff of minutes, or a few days - I need it to be accurate upto the minute
strDateTime1 = "201507212215"
strDateTime2 = "201507271355"
DateTime.DateFormat = "yyyyMMddHHmm"
' DateTime.TimeFormat = "yyyyMMddHHmm"
' Error on following line: Unparseable date (at offset 12) .....
lngDateTime1 = DateTime.DateTimeParse(strDateTime1, strDateTime1)
lngDateTime2 = DateTime.DateTimeParse(strDateTime2, strDateTime2)
Log(lngDateTime1)
Log(lngDateTime2)
lPeriod=DateUtils.PeriodBetween(lngDateTime1, lngDateTime2)
Log(lPeriod.Years)
Log(lPeriod.Months)
Log(lPeriod.Days)
Log(lPeriod.Hours)
Log(lPeriod.Minutes)
Log(lPeriod.Seconds)
Thanks in advance!
Edit: Changed accuracy from seconds to minutes (it was originally seconds, but after all these problems, if I get diff in minutes, it will do.
Last edited: