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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate Age 1

Status
Not open for further replies.

NorthNone

Programmer
Jan 27, 2003
445
0
0
US
Any ideas on how to make WebFocus calculate a true age? Calculating days between date of birth and today always messes up as you get close to the current month and day due to leap years and skipped leap years (2000).
Here's how Access does it:
Age: DateDiff("yyyy",[DOB],Date())+(Date()<DateSerial(Year(Date()),Month([DOB]),Day([DOB])))

"Character cannot be developed in ease and quiet. Only through experience of trial and suffering can the soul be strengthened, ambition inspired, and success achieved." - Helen Keller
 
North, its really easy.
are your dates "smart dates"? or "legacy dates"?
legacy date exists in the database as YYYYMMDD, for example, but "smart dates" exist in the database in the same way that they exist in Access or in Excel, or in Unix.
You can do straight arithmetic with them.
A "smart date" is, by def, the number of days elapsed since some base date.
If your dates are legacy dates, convert them using the DATECVT function.

 
Thanks for taking time to post on this question.
Once you calculate the number of days between two dates, you'll have to divide by something to come up with the number of years. If divide by 365 days, you'll ignore leap years. If you divide by 365.25 to try to account for leap years, you'll still be affected by how many leap years fall within any two dates. If I span five years and there are two leap years in that five years, I come up with one result. If there is only one leap year, I come up with another result.
I hope this makes sense as to what I am trying to get to.
Thanks again!


"Character cannot be developed in ease and quiet. Only through experience of trial and suffering can the soul be strengthened, ambition inspired, and success achieved." - Helen Keller
 
First you have to determine HOW an age is calculated. For example, if my birthday is January 30, but it's only January 29, what's my age? Is it as of a year ago, or as of tomorrow?

Perhaps the 'easiest' way is to consider everything 'as of' the 'end of the month'.

Thus, If I'm within my 'birthday month', consider it 'as if' I've reached my birthday. This also eliminates the issue caused by each month having a different number of days.

If you get the current date in a YYM format, and convert the birthdate to a YYM format, then a simple subtraction gives the number of months old. Dividing by 12 and truncating, gives you have the age.
 
I want to calculate the age precisely, in the manner a six-year old does it: Today I am six, tomorrow is my birthday and I turn seven.
The Microsoft Access function does that for me.
I want to know if that precision can be obtained in WebFOCUS.


"Character cannot be developed in ease and quiet. Only through experience of trial and suffering can the soul be strengthened, ambition inspired, and success achieved." - Helen Keller
 
Well, if that's what you want, there are TWO functions, depending on the format of your dates.

If they're only 'date' formats (no time), then the DATEDIF routine will give you what you want. It finds the difference between 2 dates.For years, the syntax is:

YEARS = DATEDIF(fromdate,todate,'Y')

The dates have to be in 'smart-date' format. The last argument says to return the difference in years. The result is whole numbers, truncated.

If the dates are a DATE-TIME format, use the HDATE routine to strip off the date component. The syntax is:

DATE/YYMD = HDATE(date_time_field,'YYMD')

 
Thanks, FocWizard. I'll give it a try.
BTW, your phrase "if that's what you want," makes me wonder when and why someone wouldn't want a precise calculation. Maybe I'm missing an obvious business rule or assumption here? Gratefully, NorthNone

"Character cannot be developed in ease and quiet. Only through experience of trial and suffering can the soul be strengthened, ambition inspired, and success achieved." - Helen Keller
 
The phrase was only meant to indicate that your request could be satisfied (no other implications intended).
 
Thanks for the clarification. One less thing to think about.
Have a great day.

"Character cannot be developed in ease and quiet. Only through experience of trial and suffering can the soul be strengthened, ambition inspired, and success achieved." - Helen Keller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top