Search
 
SCRIPT & CODE EXAMPLE
 

SQL

postgresql calculate age from birthdate

SELECT EXTRACT(YEAR from AGE(NOW(), birth)) as "age", * FROM customers;
Comment

calculate age in sql postgresql

#THIS WORKS FOR POSTGRES and MYSQL
# 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

PREVIOUS NEXT
Code Example
Sql :: flask sqlalchemy filter multiple conditions 
Sql :: mysql regex replace 
Sql :: install mysql workbench ubuntu 20.04 
Sql :: sql add column to table 
Sql :: oracle trigger after logon on schema 
Sql :: create table in mysql 
Sql :: calculate distance between two latitude longitude postgresql 
Sql :: oracle sql date get month 
Sql :: start mysql 
Sql :: Alter table add column in SQL Server- NAYCode.com 
Sql :: count mysql 
Sql :: oracle sql create table from select 
Sql :: truncate function in sql oracle 
Sql :: search for replace in mysql 
Sql :: inner join sql oracle 
Sql :: get current month last date in sql server 
Sql :: SQL Modify Column in a Table -MySQL 
Sql :: how to extract year from date in sql 
Sql :: mysql generate uuid 
Sql :: sql server output parameter 
Sql :: remove user and their privileges postgres 
Sql :: sql pagination 
Sql :: mysql compare datetime to another datetime 
Sql :: kill a pid redshift 
Sql :: oracle add time to date 
Sql :: alter table name sql 
Sql :: duplicate entry 
Sql :: oracle sql drop column if exists 
Sql :: rename table name 
Sql :: sql all 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =