Answer the question
In order to leave comments, you need to log in
How to make sql selection by age having only date of birth?
Good afternoon, please tell me how to make a choice of clients, for example, who are 50 years old.
A solution like
YEAR(DOB) = (YEAR(NOW()) - 50) Doesn't work because I need to be sure that the person is 50 full years old.
Answer the question
In order to leave comments, you need to log in
Age:
DATEDIFF( Year, BirthDay, ISNULL( DeathDay, GETDATE()))
+ ( SIGN ( DATEDIFF ( DAY, BirthDay, DATEADD ( YEAR, YEAR( BirthDay )
- YEAR( ISNULL( DeathDay, GETDATE())), ISNULL( DeathDay, GETDATE())))) - 1 ) / 2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question