sql server - Calculate Age of user WITH Datediff (?) -
i'm trying use datediff function give me years off user more complicated thought.
select datediff( dd,'1963-07-22','2016-07-23')
this give me 19360 days think because 2016 have leap year , fine.
what year , not days.
if change interval dd yy(yyyy) calculates year.
the correct answer calculate someone's age, or difference in truncated years between 2 dates
year(@today)-year(@birthdate)+floor((month(@today)-month(@birthdate)+floor((day(@today)-day(@birthdate))/31))/12);
this work regardless of leap years. , correct whether person born on later month or later day in same month. ignore hours , minutes, should when calculating someone's age.
Comments
Post a Comment