GBase 8c 函数和操作符 - 时间和日期处理函数和操作符 之 时间/日期函数

timeofday()和clock_timestamp()相似,timeofday()也返回真实的当前时 间,但是它的结果是一个格式化的text串,而不是timestamp with time zone值。timestamp类型:abstime、date、interval、reltime、time with time zone、time without time zone、timestamp with time zone、timestamp without time zone。描述:获取月份的值。
摘要由CSDN通过智能技术生成

  • age(timestamp, timestamp)

描述:将两个参数相减,并以年、月、日作为返回值。若相减值为负,则函数返回亦为负。两个参数类型必须相同,可以都带timezone,或都不带timezone。

返回值类型:interval

示例:

gbase=# SELECT age(timestamp '2001-04-10', timestamp '1957-06-13');

           age           

-------------------------

 43 years 9 mons 27 days

(1 row)

  • age(timestamp)

描述:当前时间和参数相减,入参可以带或者不带timezone。

返回值类型:interval

示例:

gbase=# SELECT age(timestamp '1957-06-13');

           age

-------------------------

 64 years 11 mons 4 days

(1 row)

  • clock_timestamp()

描述:实时时钟的当前时间戳。

返回值类型:timestamp with time zone

示例:

gbase=# SELECT clock_timestamp();

        clock_timestamp

-------------------------------

 2022-05-17 16:34:14.629575+08

(1 row)

  • current_date

描述:当前时间。

返回值类型:date

示例:

gbase=# SELECT current_date;

    date

------------

 2022-05-17

(1 row)

  • current_time

描述:当前时间。

返回值类型:time with time zone

示例:

gbase=# SELECT current_time;

       timetz

--------------------

 16:35:00.099149+08

(1 row)

  • current_timestamp

描述:当前日期及时间。

返回值类型:timestamp with time zone

示例:

gbase=# SELECT current_timestamp;

        pg_systimestamp

-------------------------------

 2022-05-17 16:35:08.018834+08

(1 row)

  • date_part(text, timestamp)

描述:获取日期/时间值中子域的值,例如年或者小时的值。等效于extract(field from timestamp)。

timestamp类型:abstime、date、interval、reltime、time with time zone、time without time zone、timestamp with time zone、timestamp without time zone。

返回值类型:date

示例:

gbase=# SELECT date_part('hour', timestamp '2001-02-16 20:38:40');

 date_part

-----------

        20

(1 row)

  • date_part(text, interval)

描述:获取日期/时间值中子域的值。获取月份值时,如果月份值大于12,则取与

12的模。等效于extract(field from timestamp)。

返回值类型:double precision

示例:

gbase=# SELECT date_part('month', interval '2 years 3 months'); 

date_part

-----------

3

(1 row)

  • date_trunc(text, timestamp)

描述:截取到参数text指定的精度。

返回值类型:interval、timestamp with time zone、timestamp without time zone

示例:

gbase=# SELECT date_trunc('hour', timestamp '2001-02-16 20:38:40');

 date_trunc

---------------------

 2001-02-16 20:00:00

(1 row)

  • trunc(timestamp)

描述:默认按天截取。示例:

gbase=# SELECT trunc(timestamp '2001-02-16 20:38:40');

trunc

---------------------

2001-02-16 00:00:00

(1 row)

  • trunc(arg1, arg2)

描述:截取到arg2指定的精度。

arg1类

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值