How to calculate age in T-SQL with years, months, and days

后端 未结 24 2055
无人共我
无人共我 2020-11-22 05:42

What would be the best way to calculate someone\'s age in years, months, and days in T-SQL (SQL Server 2000)?

The datediff function doesn\'t handle year

24条回答
  •  隐瞒了意图╮
    2020-11-22 06:14

    There is another method for calculate age is

    See below table

        FirstName       LastName    DOB
        sai             krishnan    1991-11-04
        Harish          S A         1998-10-11
    

    For finding age,you can calculate through month

      Select datediff(MONTH,DOB,getdate())/12 as dates from [Organization].[Employee]
    

    Result will be

    firstname   dates
    sai         27
    Harish      20
    

提交回复
热议问题