Home Forums SQL Server 2008 T-SQL (SS2K8) Is there an accurate script for datediff format in years:months:days? RE: Is there an accurate script for datediff format in years:months:days?

  • select [Years] = datediff(year,0,ET-ST)-1,

    [Months] = datepart(month,ET-ST)-1,

    [Days] = datepart(day,ET-ST)-1

    from

    (

    select -- Test Data

    ST = convert(datetime,'2011/01/01'),

    ET = convert(datetime,'2013/01/13')

    ) a

    Gives 1 year, 0 months and 13 days.