【AntDB数据库 SQL语法专栏】——常用函数(6)日期/时间函数

日期/时间函数
函数返回类型描述例子结果
age(timestamp, timestamp)interval减去参数,生成一个使用年、月(而不是只用日)的“符号化”的结果age(timestamp ‘2001-04-10’, timestamp ‘1957-06-13’)43 年 9 月 27 日
age(timestamp)interval从current_date(在午夜)减去age(timestamp ‘1957-06-13’)43 years 8 mons 3 days
clock_timestamp()timestamp with time zone当前日期和时间(在语句执行期间变化)
current_datedate当前日期
current_timetime with time zone当前时间(一天中的时间)
current_timestamptimestamp with time zone当前日期和时间(当前事务开始时)
date_part(text, timestamp)double precision获得子域(等价于extract)date_part(‘hour’, timestamp ‘2001-02-16 20:38:40’)20
date_part(text, interval)double precision获得子域(等价于extract)date_part(‘month’, interval ‘2 years 3 months’)3
date_trunc(text, timestamp)timestamp截断到指定精度date_trunc(‘hour’, timestamp ‘2001-02-16 20:38:40’)2001-02-16 20:00:00
date_trunc(text, timestamp with time zone, text)timestamp with time zone在指定的时区截断到指定的精度date_trunc(‘day’, timestamptz ‘2001-02-16 20:38:40+00’, ‘Australia/Sydney’)2001-02-16 13:00:00+00
date_trunc(text, interval)interval截断到指定精度date_trunc(‘hour’, interval ‘2 days 3 hours 40 minutes’)2 days 03:00:00
extract(field from timestamp)double precision获得子域extract(hour from timestamp ‘2001-02-16 20:38:40’)20
extract(field from interval)double precision获得子域extract(month from interval ‘2 years 3 months’)3
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值