Calculating Age from date of birth

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 304
DECLARE	@Sample TABLE
(
Birthday DATE NOT NULL
);

INSERT @Sample
(
Birthday
)
VALUES ('19940704'),
('19950911'),
('19941010'),
('20120731'),
('20120801'),
('19990221');

-- code
SELECT BirthDay,
DATEDIFF(YEAR, Birthday, GETDATE()) - (100 * MONTH(Birthday) + DAY(Birthday) - 1) / 801 AS Age
FROM @Sample;

Comments or Responses

Login to post response