Imagine I have a field DOB which stores date of birth of an employee.
Is there a query to find out the AGE of the employees?
The output that I want is
EmpNo Age
1 30
I am using MySQL
Imagine I have a field DOB which stores date of birth of an employee.
Is there a query to find out the AGE of the employees?
The output that I want is
EmpNo Age
1 30
I am using MySQL
DATEDIFF(day,DOB,GETDATE())/365.242199)
It's best if you put this into a function. Hope this helps.
If all you want is year and are not worried about months
SELECT EmpNo, DATEDIFF(YEAR, DOBFIELD, GETDATE()) As Age From Table
Sorry I gave the MSSQL version
Try
SELECT EmpNo, FLOOR(DATEDIFF(GETDATE(),DOBFIELD)/365) Age From Table