Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Detailed Date Calculation

Author  Topic 

janderson206
Starting Member

4 Posts

Posted - 2007-07-25 : 10:00:09
Hello,

if a customer DOB is 1933-06-30 and a date of service is on 2007-06-21
that makes them 73 and not 74. How do I calculate an accurate years of age?

Thanks in advance.

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-07-25 : 10:09:21
This function returns age in format YYYY MM DD.
Age Function F_AGE_YYYY_MM_DD:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=62729

This function returns age in years.
Age Function F_AGE_IN_YEARS:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=74462





CODO ERGO SUM
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-25 : 10:09:35
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=74462


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-25 : 10:10:11



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

janderson206
Starting Member

4 Posts

Posted - 2007-07-25 : 10:50:19
Those are great examples but I have the dates stored in the database to calculate against. What is an example of using that function in a query?
Go to Top of Page

janderson206
Starting Member

4 Posts

Posted - 2007-07-25 : 10:54:13
The goal is to calculate based on a record

select
dbo.F_AGE_IN_YEARS( a.ScheduledDTTM, a.DateOfBirth) as AGE,
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-07-25 : 11:17:47
quote:
Originally posted by janderson206

Those are great examples but I have the dates stored in the database to calculate against. What is an example of using that function in a query?



The link I supplied has an example of using the function in a query.


CODO ERGO SUM
Go to Top of Page

janderson206
Starting Member

4 Posts

Posted - 2007-07-25 : 11:51:54
I was able to do what I wanted in SQL with the example you gave. Thanks.

Now the sad part is I have to get that into crystal reports and from what I am reading you can't edit the sql code it generates. Pretty lame if thats true.
Go to Top of Page
   

- Advertisement -