I am trying to check the Age of a user from the Date Of Birth to make sure Age is between 16 and 80, When the data is inserted into the table
The Date of Birth is a DATE datatype
I have tired looked for multiple solutions and none of them check it when the data is inserted
I have found this help out article to get the current Date with only the Date: https://learnsql.com/cookbook/how-to-get-the-current-date-without-time-in-t-sql/#:~:text=To get the current date and time in SQL Server,20 10:22:34 .
But i can't seem to get it to work with the CHECK function when creating the table
CodePudding user response:
Something like:
DATEDIFF(year, DateOfBirth, GETDATE()) BETWEEN 16 AND 80
Not final code, but could be inserted in your scenario hopefully :)