📜  在sql代码示例中计算年龄

📅  最后修改于: 2022-03-11 15:04:51.959000             🧑  作者: Mango

代码示例1
#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,' '))