select a.DOB, a.CURR_DATE, Age = datediff(yy,a.DOB,a.CURR_DATE) + case -- Age is null when DOB before current date when datediff(dd,a.DOB,a.CURR_DATE) < 0 then null -- Subtract 1 if current date before birthday in current year when datediff(dd,dateadd(yy,datediff(yy,a.DOB,a.CURR_DATE),a.DOB),a.CURR_DATE) < 0 then -1 else 0 endfrom ( -- Test Data select DOB =convert(datetime,'20040407'), CURR_DATE = convert(datetime,'20060203') union all select getdate(),dateadd(ms,100,getdate()) union all select getdate(),dateadd(ms,-100,getdate()) union all select getdate(),dateadd(dd,-1,getdate()) union all select getdate(),dateadd(yy,10,dateadd(ms,-100,getdate())) union all select getdate(),dateadd(yy,10,dateadd(ms,100,getdate())) union all select '20040407','20040407' union all select '20040407','20050406' union all select '20040407','20050407' union all select '20040229','20060227' union all select '20040229','20060228' union all select '20040229','20060301' union all select '20040229','20080228' union all select '20040229','20080229' union all select '20060205','20060205' union all select '17530101 00:00:00.000','99991231 23:59:59.997' union all select '19500913', getdate() ) aorder by a.DOB, a.CURR_DATE
DOB CURR_DATE Age----------------------- ----------------------- -----------1753-01-01 00:00:00.000 9999-12-31 23:59:59.997 82461950-09-13 00:00:00.000 2013-01-08 16:52:54.810 622004-02-29 00:00:00.000 2006-02-27 00:00:00.000 12004-02-29 00:00:00.000 2006-02-28 00:00:00.000 22004-02-29 00:00:00.000 2006-03-01 00:00:00.000 22004-02-29 00:00:00.000 2008-02-28 00:00:00.000 32004-02-29 00:00:00.000 2008-02-29 00:00:00.000 42004-04-07 00:00:00.000 2004-04-07 00:00:00.000 02004-04-07 00:00:00.000 2005-04-06 00:00:00.000 02004-04-07 00:00:00.000 2005-04-07 00:00:00.000 12004-04-07 00:00:00.000 2006-02-03 00:00:00.000 12006-02-05 00:00:00.000 2006-02-05 00:00:00.000 02013-01-08 16:52:54.810 2013-01-07 16:52:54.810 NULL2013-01-08 16:52:54.810 2013-01-08 16:52:54.710 02013-01-08 16:52:54.810 2013-01-08 16:52:54.910 02013-01-08 16:52:54.810 2023-01-08 16:52:54.710 102013-01-08 16:52:54.810 2023-01-08 16:52:54.910 10