Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ROUND FUNCTION: DOWN TO WHOLE NUMBER? 2

Status
Not open for further replies.

UberZoot

Technical User
May 31, 2003
29
0
0
US
Ladies and Gents,
I have a query that calculates age by subtracting Date of Birth from Date(). The result appears in days and I divide this by 365.25 to calc years (accounting for leap year with the .25). This number needs to appear sans decimals, but it gets rounded up once the person hits over their half-year mark. Is there a way to use the Round function to round these numbers down and truly show how old an individual is by years? Thanks in advance.

UZ
 
Try this:

FORMATNUMBER(YourResult,2) which gives you 2 decimals precision.

-VJ
 
Use this expression to calculate the AGE:

Code:
Age: IIf(Month([dob])=Month(Date()) And Day([dob])=Day(Date()),CInt((DateDiff('d',[dob],Date())/365.25)),CInt((DateDiff('d',[dob],Date())/365.25)-0.5))

This expression takes into account all of the issues you have stated. You must calculate the age differently when not exactly on the date of birth.

Give it a try.

Bob Scriver
[blue]Want the best answers? See FAQ181-2886[/blue]


 
Try the integer function:

Int(yourresult)

Only returns the integer portion of a number with no rounding.

Susan
 
Technically, a year is 365.24219 days, not 265.25. Using .25 does not take into account the 3 out of 4 years divisible by 100 that are not leap years.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Or, my favorite, courtesy of The Access Web:

Code:
Age=DateDiff("yyyy",[Bdate],date())+Int(Format(date(),"mmdd")<Format([Bdate],"mmdd"))



HTH,
Bob [morning]
 
And ... this has been extensively (EXHAUSTIVELY?) discussed in htese (and probably ever sight on tghe face of the ball of mud) Search for most any all of the relevant terms and recieve a plethora of advice:

Sugested Terms:
AGE

DOB

Birthdate






MichaelRed
mlred@verizon.net

 
MichaelRed,

It can't be "exhaustively" if it continues to be asked on a regular basis... [peace]

I (others?) rarely visit the FAQ's. Instead I rely on "Advanced Search". Maybe a proven set of Expressions and Functions for age and years/months/days/time elapsed posted as a FAQ and THEN when threads are initiated the person with the question could be referred to the common FAQ? [thumbsup]

Michael, obviously, you're bored-with/tired-of the exercise. Please consider the number of almost-correct posts we (the continuing-to-learn set) have to look at, copy, test, discard before arriving at problem solution regarding date handling. [hourglass]


HTH,
Bob [morning]
 
Dear Bob, et al;

To some degree, yes bored with / tired of. On the other hand, MY posting of just MY (favoite?) soloution here, now, specifically does little more than add to the profusion of what is already at your disposal. Awaiting that same retrieve, 'understand', test, evaluate, discard cycle. I try to only provide a specific direct answer when I believe that the post may actually relieve some part of that process. In this case, it certainly wouldn't. These 'answers' are available throughout the threads as well as the FAQ's, so your (advertized) approach should have retrieved a surfit of approaches for you to sift through.




MichaelRed
mlred@verizon.net

 
Thanks Scriverb,
I was just looking around and came across your code based on DOB and wanted to let you know it's terrific! :eek:) Much better and straight forward then what I usually use.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top