I was looking at the Users Guide but still can't figure out how to parse dates to get how many days. I want to set a date (Long) when my app first installs then check this date against today's date to determine if the trial period has expired. I want a 30 day trial period.
All dates and timestamps in B4A are internally stored in Ticks, i. e. a long number representing the time/date in milliseconds. So you can use dates/times like numbers and can calc differences using simply math.
Example:
B4X:
DateNow = ...
DateInstalled = ...
NumberOfDays = (DateNow - DateInstalled) / 86400000
If NumberOfDays > 30 Then
'Trial period expired...
Else
'Valid trial period...
End If
I was looking at the Users Guide but still can't figure out how to parse dates to get how many days. I want to set a date (Long) when my app first installs then check this date against today's date to determine if the trial period has expired. I want a 30 day trial period.
If you want to use your datetime.add function, here is a method that yields the same result as Jost and Klaus, but with a different flavor:
B4X:
'BELOW To CALCULATE IF 30 DAY TRIAL PERIOD EXPIRED
Dim DateInstalled As String
DateInstalled = "4/20/2012"
If DateTime.Add(DateTime.dateparse(DateInstalled),0,0,30)< DateTime.Now Then
'Trial period expired...
Msgbox("Expired","")
Else
'Valid trial period...
Msgbox("Not Expired","")
End If