×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

CALCULATING AGE AT A SPECIFIED DATE
2

CALCULATING AGE AT A SPECIFIED DATE

CALCULATING AGE AT A SPECIFIED DATE

(OP)
I have a database where I need to calculate the members age (in years and months) as of a specific date (6/1/2018 )
I am using BDATE and SDATE as my fieldnames

Example - MEMBER with BDATE of 7/1/2010 would return a value of 8.1
MEMBER with BDATE OF 5/1/2010 would return a value of 7.11

Thanks in advance for your help.

RE: CALCULATING AGE AT A SPECIFIED DATE

Quote:

Example - MEMBER with BDATE of 7/1/2010 would return a value of 8.1
MEMBER with BDATE OF 5/1/2010 would return a value of 7.11
I think you mean
Example - MEMBER with BDATE of 7/1/2010 would return a value of 7.11
MEMBER with BDATE OF 5/1/2010 would return a value of 8.1

Years.Months is a strange value to show. I think you would be better off without the decimal. Kind of confusing. The below function can be called from a query. It accounts for full months and corrects for leap years.
"Select YearsDecimalMonths([bdate],[sdate]) as Age, otherFields, from someTable"

CODE -->

Public Function YearsDecimalMonths(ByVal StartDate As Date, ByVal EndDate As Date) As Variant
  Dim intDiff   As Integer
  Dim intMonths As Integer
  Dim intSign As Integer
  ' Find difference in calendar months.
  intMonths = DateDiff("m", StartDate, EndDate)
  ' Check if the second date falls before, on, or after the crossing date for a 1 month period
  ' while at the same time correcting for February 29. of leap years.
  intSign = Sgn(DateDiff("d", DateAdd("m", intMonths, StartDate), EndDate))
  intDiff = Abs(intSign < 0)
   ' Return count of months as count of full 1 month periods.
  Months = intMonths - intDiff
  YearsDecimalMonths = Months \ 12 & "." & Months Mod 12
  ' YearsDecimalMonths = Months \ 12 & " Years " & Months Mod 12 & " Months"
End Function 

RE: CALCULATING AGE AT A SPECIFIED DATE

(OP)
Thank you MajP - this works perfectly!!!

RE: CALCULATING AGE AT A SPECIFIED DATE

w0wsmg,

It's appropriate to click the "Treat post!" link to indicate the thread has been resolved and it gives some kudos to MajP.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close