Forum Replies Created

Viewing post 1 (of 1 total)

  • RE: Working Out Exact Age with DateDiff

    Try this

    DECLARE @FrmDate date = '31dec2009'

    ,@EndDate date = '01jan2010'

    SELECT

    CASE WHEN DATEpart(MM,@FrmDate)=DATEpart(MM,@EndDate)

    THEN CASE WHEN DATEpart(DD,@FrmDate)>DATEpart(DD,@EndDate)

    THEN datediff(MM,@FrmDate,@EndDate)/12 - 1

    ELSE datediff(MM,@FrmDate,@EndDate)/12

    END

    ELSE datediff(MM,@FrmDate,@EndDate)/12

    END

Viewing post 1 (of 1 total)