Hakan Axheim

Hakan Axheim

  • NA
  • 201
  • 32.9k

Calculate age between current date and birthdate

Feb 22 2019 5:53 AM
Hi,
 
I want to calcute the diffence between current date and the date a person is born in year.
Birthday is stored in a column with vachar(12).
 
I try this SQL statement:
 
SELECT CONVERT(DATETIME,LEFT(birthdate,8),120), DATEDIFF(YEAR,CONVERT(DATETIME,LEFT(birthdate,8),120),getdate()) as 'Age' from Person
 
The funny thing with this SQL is if a person is born 201809234247  (social security number) and the current date is 2019-02-22 the age result will be 1 year. This is not true - it should be 0.
 
Something is wrong with my SQL statement but what?

Answers (4)