Android Question DateUtils - PeriodBetween

LucaMs

Expert
Licensed User
Longtime User
adpUserBirth is an AnotherDatePicker:
B4X:
Sub adpUserBirth_DateChanged (NewDate As Long)
    DateTime.DateFormat = "MM/dd/yyyy" ' just to be sure
    Dim PerDiff As Period
    PerDiff = DateUtils.PeriodBetween(NewDate, DateTime.Now)
    Log("New date: " & DateTime.Date(NewDate))
    Log("Today   : " & DateTime.Date(DateTime.Now))
    Log("Days diff.: " & PerDiff.Days)
End Sub

Log:
New date: 10/11/1960
Today : 04/18/2018
Days diff.: 7

So, I am 7 days old :p

Where is my error?
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
Found right now this:
upload_2018-4-18_23-44-56.png


and it seems to work.

But then I don't know the differences between the two functions.



[So I am 21,008 days old :(]
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
The first code should be like this:
B4X:
DateTime.DateFormat = "MM/dd/yyyy" 
    Dim PerDiff As Period
    PerDiff = DateUtils.PeriodBetween( DateTime.Dateparse("10/11/1960"), DateTime.Now)
    LogColor($"${PerDiff.Years} years ${PerDiff.Months} months ${PerDiff.Days} days"$, Colors.Blue )  '57 years 6 months 7 days
 
Upvote 0
Top