kasper Posted January 31, 2006 Share Posted January 31, 2006 hi all ,i am making a program with database , and i need a SQL satatement to:Calculate the age of persons in years , months and daysthe age is betwwn the birthdays and 5/12/2006for example : Goerge age is 30 years, 3 months and 24 days Link to comment Share on other sites More sharing options...
aspnetguy Posted January 31, 2006 Share Posted January 31, 2006 What is your database/table structure???? Link to comment Share on other sites More sharing options...
kasper Posted February 1, 2006 Author Share Posted February 1, 2006 i have a table of 1 column , the datatype of this column is Date/Time Link to comment Share on other sites More sharing options...
aspnetguy Posted February 1, 2006 Share Posted February 1, 2006 Well you will need another column with the persons name...I am assuming that the column you have of DateTime is their birthday??? Link to comment Share on other sites More sharing options...
kasper Posted February 1, 2006 Author Share Posted February 1, 2006 Yes , you are right. i have a column with thier names called Name and another column called Birthday Link to comment Share on other sites More sharing options...
aspnetguy Posted February 1, 2006 Share Posted February 1, 2006 SELECT Name,Birthday,(DATEDIFF("dd",Birthday,getdate())/365) AS Years,(DATEDIFF("dd",Birthday,getdate())/365*12) AS Months,(DATEDIFF("dd",Birthday,getdate())) AS DaysFROM People Well I played around with this query I made but just can't get the math right. It givews the total years, total months , and total days...not what you are looking for but I found this article that has a T-SQL function to get the exact number of years, months, and days are between 2 dates.http://www.dnzone.com/forum/topic.asp?topic_id=156I hope this at least gets you started. Link to comment Share on other sites More sharing options...
kasper Posted February 1, 2006 Author Share Posted February 1, 2006 Thank you for the link Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now