开发者

To get the age from date of birth in SQL Server

I have 3 columns with Age, month, Date of Birth I want to get Age from DateofBirth textbox using stored procedure calculate age with month inser开发者_如何学JAVAted.

eg:

DateofBirth = 25/05/1987 (DD/MM/YYYY)
Age=24
Month=3

plz give solution

Thanks in advance!


Checkout the following post:

Get Age from Date of Birth

I have used the method described to retrieve the age and then used the DATEPART function to retrieve the month.

DECLARE @dateOfBirth DATETIME
SET @dateOfBirth = '05/25/1987'

DECLARE @age INT
SET @age =  FLOOR(DATEDIFF(DAY, @dateOfBirth, GETDATE()) / 365)

DECLARE @month INT
SET @month = DATEPART(MM, @dateOfBirth)

SELECT @age as Age, @month as [Month]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜