Age Calculation

Viewing 9 reply threads
  • Author
    Posts
  • March 25, 2018 at 6:19 AM #27982

    Aik Pin Ng
    Participant

    Hi,

    I have a field that stores the year a building was built. E.g. 1998. I want to have another field to auto calculate the age of the building. e.g. Current year (i.e 2018) minus the year built (e.g. 1998). In this example, the field will display “20”.

    How do I do that?

    Thanks!
    Aik Pin

    March 25, 2018 at 8:22 AM #27983

    Aik Pin Ng
    Participant

    To be more specific, can you show me the formula to use on the calculation field?

    Thanks.

    March 25, 2018 at 10:26 AM #27984

    Brendan
    Keymaster

    Hello Aik,

    In the most recent versions of Tap Forms 5 (I forget when I added it), you can use the YEARS() function to get the number of years between two dates.

    E.g. YEARS(Build Date; TODAY()

    That will return a Number value.

    To be more precise, you can use this formula:

    YYMM(Build Date; TODAY())

    That returns Text of the number of years and months between the dates.

    E.g. 10 years, 3 months

    March 26, 2018 at 6:19 PM #27992

    Aik Pin Ng
    Participant

    Hi Brendan,

    I tested with

    YEARS(Year; TODAY())

    where Year is the name of the field.

    No matter whether the year is 1991,1996, 1992, it all returns “48”.

    Any idea why?

    Thks!
    Aik Pin

    March 26, 2018 at 7:03 PM #27993

    Brendan
    Keymaster

    It should work. I just tested it. But if you provide an empty date, then you’ll get 48 because that’s how many years have passed since January 1, 1970 00:00:00 GMT.

    You can modify the formula like this:

    IFEMPTY(Year; 0; YEARS(Year; TODAY()))

    That will return 0 if Year is empty.

    March 26, 2018 at 7:42 PM #27995

    Aik Pin Ng
    Participant

    Mmm…it stills return 48.

    The “Year” is set as Type “Number”.

    Does it make any difference?

    Attachments:
    You must be logged in to view attached files.
    March 26, 2018 at 9:24 PM #27997

    Brendan
    Keymaster

    Yes. Year should be a date field for my formula to work. Sorry I didn’t realize your Year field was a Number field.

    So instead, you need to use the NEWDATE() function to convert your Year field into a Date field.

    NEWDATE(Y;M;W;WD;WO;D;H;M;S)

    Y = Year, M = Month, W = Week of Year, WD = Weekday, WO = Week Ordinal, D = Days, H = Hours, M = Minutes, S = Seconds.|Date

    So what you could do is:

    IFEMPTY(Year; 0; YEARS(NEWDATE(Year; 1; 0; 0; 0; 1; 0; 0; 0); TODAY())))

    That will convert your Year field into Year-01-01, where Year is the field. So basically January 1, whatever year from the Year field.

    Now that you have 2 dates, you can use the YEARS() function to calculate the years between the dates.

    March 26, 2018 at 9:30 PM #27998

    Brendan
    Keymaster

    I guess it would be useful to have functions to extract out the units from a Date field as a number value.

    E.g. YEAR(TODAY()) would return 2018, MONTH(TODAY()) would return 3, etc.

    March 26, 2018 at 10:41 PM #27999

    Aik Pin Ng
    Participant

    Thanks! It works now! :)

    March 26, 2018 at 11:33 PM #28000

    Brendan
    Keymaster

    Excellent!

Viewing 9 reply threads

You must be logged in to reply to this topic.