Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I've a table "user" with attributes:Date of Birth ,@DOBDate of Registration ,@Registration_DateNow 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 userORselect datediff(month, [Date of Birth], getdate()) / 12.0from user
KH[spoiler]Time is always against us[/spoiler]
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.
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2011-07-20 : 23:02:50
getdate() is a system function that will return the current datedatediff will return the different between 2 datesKH[spoiler]Time is always against us[/spoiler]
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 MVJMadhivananFailing to plan is Planning to fail
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.
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/