Hakan Axheim

Hakan Axheim

  • 1.8k
  • 115
  • 6.7k

Calculate age between current date and birthdate

Feb 22 2019 5:53 AM
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?

Brought to you by: JavaScript SDK for Bold BI dashboard and analytics embedding. Free trial.

Answers (4)