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)

Answers


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

WHERE DateDiff(month,CONVERT(datetime,'19951118',112),getdate())>=18*12

SQLFiddle demo


Need Your Help

Google Drive API 401 when trying to download a file

oauth-2.0 google-drive-sdk google-oauth google-api-php-client

I'm using the google-api-php-client to get the URL for a document on my Google Drive. The URL works correctly when I paste it into my browser and I can download the file.

Checkbox is always coming as unchecked

jquery asp.net-mvc kendo-ui kendo-grid telerik-mvc

I have following Kendo Grid ans associated jQuery. On a button click, I need to know whether checkbox is checked. But at present it is showing 'false' always. How can we correct it?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.