Search
 
SCRIPT & CODE EXAMPLE
 

SQL

calculate age in sql

#THIS IS FOR POSTGRES
# You can use the AGE function. The AGE function requires two arguementS.
# AGE(late date, early date). The NOW() function returns the current timestamp.

AGE(NOW(), date_of_birth) AS age

#Since NOW() is a timestamp, the result will be like this:
# 45 years 2 months 15 days 21:43:05.378372
#You can then use this to extract the age.

LEFT(age, STRPOS(age,' ')) 
Comment

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
Comment

PREVIOUS NEXT
Code Example
Sql :: date less than current date sql 
Sql :: postgresql substring 
Sql :: date_trunc postgres 
Sql :: how to alter table column name in mysql 
Sql :: delete role postgres 
Sql :: random record using order by rand() mysql 
Sql :: oracle undotbs usage 
Sql :: how to drop a database in sql server when it is in use 
Sql :: Select last row from SQL Table 
Sql :: Insert from table tsql 
Sql :: postgres database sizes 
Sql :: oracle auto_increment 
Sql :: incorrect string value: mysql 
Sql :: sql values not in another table 
Sql :: postgresql alter table sequence 
Sql :: insert data in pgsql 
Sql :: SQL rounding numbers 
Sql :: db.Database.SqlQuery 
Sql :: sql server query all database objects 
Sql :: sql view where tables have same column name combine results 
Sql :: show constraints mysql 
Sql :: how to print mysql query of codeigniter query builder 
Sql :: csv to sqlite python 
Sql :: backup a table in sql 
Sql :: mysql subdate 
Sql :: rename field name in mysql 
Sql :: mysql case when or 
Sql :: Check user permissions on postgres database 
Sql :: sql select last id 
Sql :: mysql datetime to date 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =