Here’s a query to calculate the Age in Years, Months, Days, Hours and Minutes
declare @birth_day datetime
set @birth_day ='19660527 12:34:22'
end as days,
datepart(hour,convert(varchar(10),dateadd(minute,minutes,0),108)) as hours,
datepart(minute,convert(varchar(10),dateadd(minute,minutes,0),108)) as minutes
end as months,
convert(varchar(8),getdate(),108)) as minutes
end as years
) as t
) as t
In the query shown above, the inner query finds the year difference between current date and birth date. The case expression checks whether current month is greater than the month of birth date. If it is greater, a full year is completed, else the full year is not completed and one year is reduced from the result.
A similar check is done for month too. The outer parts calculate the hours and minutes.
Did you like this post?
|subscribe via rss||subscribe via e-mail|
|print this post||follow me on twitter|