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
 stored procedure for calculating the age

Author  Topic 

jonekim
Starting Member

35 Posts

Posted - 2011-07-20 : 22:37:02

I've a table "user" with attributes:
Date of Birth ,@DOB
Date of Registration ,@Registration_Date

Now how can I calculate the age of a user from these two attributes via Stored Procedure?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-07-20 : 22:46:33
depends on your accuracy that you want


select datediff(year, [Date of Birth], getdate())
from user

OR

select datediff(month, [Date of Birth], getdate()) / 12.0
from user




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

Go to Top of Page

jonekim
Starting Member

35 Posts

Posted - 2011-07-20 : 22:52:47
@khtan thanks for the reply.
Will you please elaborate the answer? How does it work? Is getdate() library function??

Thank You.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-07-20 : 23:02:50
getdate() is a system function that will return the current date

datediff will return the different between 2 dates


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

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-07-21 : 07:08:40
Search in Script library forum. You will find a post posted by MVJ

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jonekim
Starting Member

35 Posts

Posted - 2011-07-22 : 11:55:21
@khtan, thanks for the post.
@ madhivanan, will you provide me the link.
That will be more helpful.

Thank You.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-07-22 : 12:27:36
see


http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=62729
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=74462


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jonekim
Starting Member

35 Posts

Posted - 2011-07-23 : 08:41:51
Thanks @visakh16
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-07-23 : 08:44:18
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -