PostgreSQL常用时间函数与时间计算提取示例说明

文章目录

常用函数与常量

函数

说明

current_time

现在的时间

current_date

今天的日期

current_timestamp

当前日期和时间

now()

当前的日期和时间和current_timestamp一样

localtime

time,当前时间

localtimestamp

当前日期和时间

timeofday()

字符串,当前日期和时间

age(timestamp1, timestamp2)

计算年纪,timestamp1-timestamp2,结果类型是interval,类似于:29 years 9 mons 27 days

select current_date,current_time,current_timestamp,now(),localtime,localtimestamp,timeofday();

PostgreSQL常用时间变量

select age('2030-04-10', '2000-06-13');

第1个参数减第2个参数,age返回值是interval,很方便算年龄

PostgreSQL age函数

-- 时间戳转字符串再截取
SELECT now()::timestamp,substring(''||now()::timestamp from 1 for 19);

PostgreSQL时间截取

to_timestamp(字符串转时间戳、数字转时间戳)

函数

说明

to_timestamp(text, text)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值