Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

calculate age in sql

DATEDIFF (datepart, start, end)

Select *,  DATEDIFF(year, DOB,GETDATE()) as COLUMN_NAME from TABLE_NAME

GETDATE = CURRENT DATE
DOB = PATIENT'S DATA OF BIRTH
YEAR = FORMAT THAT WILL RETURN THE PATIENT AGE  FOR EXAMPLE: 21
(IF YOU PUT MONTH INSTEAD OF YEAR , IT WILL GIVE YOU THE AGE IN MONTHS, LIKEWISE FOR DAY)

FOR EXAMPLE: YEAR = 21, MONTH = 252, DAY = 7665
 
PREVIOUS NEXT
Tagged: #calculate #age #sql
ADD COMMENT
Topic
Name
5+9 =