declare @BirthDate datetime = '12/1/2016' declare @Today datetime = DateAdd(dd, DateDiff(dd, 0, getdate()), 0) declare @age int = ( CONVERT(int,CONVERT(char(8),@Today,112)) - CONVERT(char(8), @BirthDate, 112)) /10000 select @age /* returns 1 if today's date is 12/1/2017. */ /* returns 0 if today's date is 12/2/2017. */
No comments:
Post a Comment