Minggu, 25 Juli 2010

Calculate Age from Date Of Birth using SQL Server

Here’s a query to calculate the Age in Years, Months, Days, Hours and Minutesdeclare @birth_day datetimeset @birth_day ='19660527 12:34:22'select years, months, case when day(@birth_day)>day(getdate()) then day(getdate()) + datediff(day,@birth_day,dateadd(month,datediff(month,0,@birth_day)+1,0))-1 else day(getdate())-day(@birth_day) end as days, datepart(hour,convert(varchar(10),dateadd(minute,

Tidak ada komentar:

Posting Komentar