Answers for "psql age function"

SQL
1

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,' '))
Posted by: Guest on August-09-2021
1

age postgres

#Code language: SQL (Structured Query Language) (sql)
SELECT age(CAST (day_of_birth AS timestamp)) AS Age;
--0 years 0 months 0 days
SELECT (CURRENT_DATE - CAST(day_of_birth AS date))/365 age;
--0 (age_in_years)
Posted by: Guest on November-03-2021

Code answers related to "SQL"

Browse Popular Code Answers by Language