Posted on 2007-11-05 12:03
skycity 阅读(642)
评论(0) 编辑 收藏 所属分类:
数据库技术
这两天又回过头来弄postgresql发现了一个比较好用的函数
根据出生日期得到当前用户年龄
elein=# SELECT age('12/31/1959'::timestamp);
age
------------------------
43 years 7 mons 8 days
elein=# SELECT extract(year FROM age('12/31/1959'::timestamp));
date_part
-----------
43
elein=# SELECT extract(days FROM age('12/31/1959'::timestamp));
date_part
-----------
8
SELECT extract(days FROM age('12/31/1959'::timestamp));
date_trunc
------------------------
43 years 7 mons 8 days
=# SELECT date_trunc('months' ,age('12/31/1959'::timestamp));
date_trunc
-----------------
43 years 7 mons
=# SELECT date_trunc('years' , age('12/31/1959'::timestamp));
date_trunc
------------
43 years
Lyyb2001