Findout if a user is older than 18 T-SQL
I have a table that contains a birthday in the format (YYYYMMDD) eg '19951118'
What is the most efficient way to findout if the user has turned 18?
I add my solution in the post instead of a comment: SELECT * from Users where DATEADD(YEAR,18,BirthDay) > DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0)
Assuming your dateofbirth is char(8), this will perform well on a large table because there is no calculation on the column birthday.
WHERE REPLACE(CONVERT(CHAR(10), DATEADD(YEAR,-18,CURRENT_TIMESTAMP), 126), '-', '') >= birthday
If you store date of birth as a varchar then