i have seen a tutorial online which showing how to calculate ages using sql server,
there is something which i can not get it .. is the in the example code below there is condition between MOnth and day, and as my knowledge when there is "AND" between two conditions , the two conditions must be applied
but in this code blow , the second part which says the satart date > current day is not applied which means it should subtract 0 not one
Code: Select all
Declare @StartDate date
set @StartDate='12/5/2016'
begin
select DATEDIFF(year,@StartDate,GETDATE()) -
CASe
when
-- check the month and day
(MONTH(@startDate)> MONTH(GetDate()) )or (MONTH(@startDate)= MONTH(GetDate())
and
-- in this example for today today is 21 which is greater than start date day
day(@startDate) > day(GetDate()))
then 1 else 0
end
End