Results 1 to 4 of 4
  1. #1
    katc is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Oct 2015
    Location
    MN
    Posts
    3

    Calculating an Age field



    I am calculating the age of a file. I have two fields I want to calculate the difference in age or years (one is in a form and the other in a subform). The field names are: DOB and CaseDate. I used the following to calculate:

    DateDiff("yyyy", Forms!EnterPatient!DOB, Forms!EnterPatient!Case.Form!CaseDate) + (Forms!EnterPatient!Case.Form!CaseDate < DateSerial(Year(Forms!EnterPatient!Case.Form!CaseD ate), Month(Forms!EnterPatient!DOB), Day(Forms!EnterPatient!DOB)))

    However, for a file that is not yet a year, it only returns 0. Does anyone know of a way to have it return a decimal for less than a year?

    Thanks.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Why don't you use dateDiff to show Months or Days?
    Would you or anyone else relate to .038 years? (which is about 14 days)

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The "yyyy" causes the difference to be in years.
    You could use "m", which would return the number of months, then divide by 12 to get years. So if DateDiff() returned 18 months, dividing by 12 would return 1.5 years. if DateDiff() returned 6 months, dividing by 12 would result in .5 years.

  4. #4
    katc is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Oct 2015
    Location
    MN
    Posts
    3
    Steve,
    Prefect. I was just messing with "d" and then dividing by 365.25. However, "m" /12 is even better!
    Thank you for your wisdom!
    Cheers!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Calculating Multi Value field
    By Youngfighter in forum Queries
    Replies: 1
    Last Post: 12-31-2014, 07:45 AM
  2. Replies: 3
    Last Post: 09-19-2014, 08:22 AM
  3. Calculating AGE from DOB Field.
    By must90 in forum Access
    Replies: 1
    Last Post: 11-25-2012, 07:54 AM
  4. #error on field calculating value
    By burrina in forum Forms
    Replies: 20
    Last Post: 11-09-2012, 10:38 AM
  5. Calculating field from look up table
    By hmcquade in forum Forms
    Replies: 1
    Last Post: 05-20-2011, 11:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums