0

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

Random User
  • 355
  • 4
  • 8
  • 19
  • 1
    http://stackoverflow.com/questions/7749639/how-to-get-the-difference-in-years-from-two-different-dates use `now()` or `curdate()` as the second mysql docs also cover it http://dev.mysql.com/doc/refman/5.0/en/date-calculations.html – exussum Nov 19 '13 at 13:49
  • I need the calculation to be done for each employee record and display the age next to the employee number. I have shown my intent in the question – Random User Nov 19 '13 at 13:51

2 Answers2

0

DATEDIFF(day,DOB,GETDATE())/365.242199)

It's best if you put this into a function. Hope this helps.

user2554121
  • 225
  • 1
  • 7
  • 17
0

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

Fred
  • 5,663
  • 4
  • 45
  • 74