1 Reply Latest reply on Jan 28, 2013 2:10 PM by philmodjunk

    Comparing Dates



      Comparing Dates



           I'm having a real brain-fart moment.  I'd like to have a calculation that compares two dates and returns the value of "Age" in number of years.  For example

      •           1/1/13 to 1/1/14 would return 1
      •           Anything less than that would return 0
      •           Anything more than one year would return the number of years

           The issue I'm having is that if you only use the Year ( xxx) function then an item from December of last year looks like it's a year old now, even though it's only a month old.  Can someone give me a function that takes into account exactly 365 days when comparing?  I've tried a few different things and haven't had any luck.  I'm sure I'm just missing something small.

           Does this make sense?  Thanks!

        • 1. Re: Comparing Dates

               Let (  [ B = YourTable::BirthDateField ;
                           T = Get ( CurrentDate )  
                        ] ;
                           Year ( T ) - Year ( B ) - ( T < Date ( Month ( B ) ; Day ( B ) ; Year ( T ) ) )

               Substitute your birthdate field in place of "YourTable::BirthDateFiel" and make sure that this is a field of type date. Also make sure to select unstored as the storage option for this calculation field or the age will not automatically update as time passes.