×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

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!

*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

Calculate Age

Calculate Age

Calculate Age

(OP)
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

RE: Calculate Age

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.

RE: Calculate Age

(OP)
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

RE: Calculate Age

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.

RE: Calculate Age

(OP)
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

RE: Calculate Age

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')

RE: Calculate Age

(OP)
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

RE: Calculate Age

The phrase was only meant to indicate that your request could be satisfied (no other implications intended).

RE: Calculate Age

(OP)
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

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! Already a Member? Login

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