数据仓库服务 GAUSSDB(DWS)-时间/日期函数:subdate(date, interval | int)

时间:2024-01-26 16:15:18

subdate(date, interval | int)

描述:返回给定日期时间减去指定单位的时间间隔的结果; 默认单位(即第二个参数为整型时)为天数。

返回值类型:timestamp

示例:

当入参为text类型时:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
SELECT subdate('2020-11-13', 10);
  subdate
------------
 2020-11-03
(1 row)

SELECT subdate('2020-11-13', interval '2' month);
  subdate
------------
 2020-09-13
(1 row)

SELECT subdate('2020-11-13 12:15:16', interval '1' month);
       subdate
---------------------
 2020-10-13 12:15:16
(1 row)

SELECT subdate('2020-11-13', interval '2' minute);
       subdate
---------------------
 2020-11-12 23:58:00
(1 row)

当入参为date类型时:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
SELECT subdate(current_date, 10);
  subdate
------------
 2021-09-05
(1 row)

SELECT subdate(current_date, interval '1' month);
       subdate
---------------------
 2021-08-15 00:00:00
(1 row)
support.huaweicloud.com/sqlreference-820-dws/dws_06_0309.html