Android Question DateUtils - PeriodBetween

Discussion in 'Android Questions' started by LucaMs, Apr 18, 2018.

  1. LucaMs

    LucaMs Expert Licensed User

    adpUserBirth is an AnotherDatePicker:
    Code:
    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: Apr 18, 2018
  2. LucaMs

    LucaMs Expert Licensed 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: Apr 18, 2018
  3. Mahares

    Mahares Well Known Member Licensed User

    The first code should be like this:
    Code:
    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
     
    LucaMs likes this.
  4. LucaMs

    LucaMs Expert Licensed User

    This is the same thing...
    but this your line:
    opened my eyes :)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice