I could prefer to execute the above sql in the following way
Please note that I changed the query and re-code it in T-SQL
But I believe the logic of the SQL engines that will execute it the same
declare @curdate datetime = getdate()
declare @date20 datetime = dateadd(yy,-20,@curdate)
SELECT id, DATEDIFF(YEAR,dateOfBirth,@curdate) AS age
FROM [user]
WHERE dateOfBirth <= @date20
In WHERE clause I preferred to use a static variable whose value is calculated before. This type of WHERE criteria enables the use of INDEX on in our case dateOfBirth column. And this boosts the performance of the query
Otherwise, at least in SQL Server a WHERE clause like below
WHERE DATEDIFF(YEAR,dateOfBirth,@curdate) >= 20
will fail the use of INDEX on dateOfBirth column and so the query performance