欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

tencent cloud-Time Interval Functions

最编程 2024-08-04 16:04:11
...
Time interval functions perform time period-related operations, such as adding or subtracting a specified interval from a date or counting the time between two dates.
Function
Description
Example
date_add(unit,value,timestamp)
Adds N time units (unit) to timestamp. If value is a negative value, subtraction is performed.
* | SELECT date_add('day', -1, TIMESTAMP '2020-03-03 03:01:00')
The return value is the date and time one day earlier than 2020-03-03 03:01:00, i.e., 2020-03-02 03:01:00.
date_diff(unit, timestamp1, timestamp2)
Returns the time difference between two time expressions, for example, calculates the number of time units (unit) between timestamp1 and timestamp2.
* |SELECT date_diff('hour', TIMESTAMP '2020-03-01 00:00:00', TIMESTAMP '2020-03-02 00:00:00')
The return value is the time difference between 2020-03-01 and 2020-03-02, i.e., one day.
The following units (unit) are supported:
unit
Description
millisecond
Millisecond
second
Second
minute
Minute
hour
Hour
day
Day
week
Week
month
Month
quarter
Quarter of a year
year
Year
Sample
Return the interval value in seconds between '2020-03-01 00:00:00' and '2020-03-02 00:00:00':
* | SELECT date_diff('second', TIMESTAMP '2020-03-01 00:00:00', TIMESTAMP '2020-03-02 00:00:00')