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

birthdate calculation

Status
Not open for further replies.

suzmcc

Programmer
Joined
Oct 10, 2000
Messages
2
Location
US
Need to be able to calculate the age of an indivudual for example I want to find indivuduals who are 6 this year. Not six as of January 1 but 6 as of their birhtdate no matter when it falls in the year. 6 as of that date. I am using PowerBuilder 6.5, which as a function called Datediff but I need an SQL command that will perform similar actions. [sig][/sig]
 
Date functions tend to be RDBMS specific so getting a general SQL function would probably be fairly protracted.
If my memory is correct Ingres would be something like this

SELECT table.name, table.birthdate
FROM table
WHERE (table.birthdate + '6 years') > date('today'); [sig]<p>Ged Jones<br><a href= > </a><br>Top man[/sig]
 
If I understand your question you need any birthday between Jan. 1 and Dec. 31 six years ago. In Oracle you can get this with the following query.

SELECT table.name, table.birthdate
FROM table
WHERE table.birthday is between
add_months(trunc(sysdate,'yyyy'),-72)
AND
last_day(add_months(trunc(sysdate,'yyyy'),-61))
[sig][/sig]
 
How can I query age from a birthdate?
I suppose to derive the birthdate to value, but I don't know how
 
Aren't you just interested in the year portion of Birthdate? ie all the birthdates where
year(birthdate)+6 = year(systemdate) Malcolm
wynden@telus.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top