Skip to content

Commit 8c21161

Browse files
authored
TIMESTAMP_DIFF (#1640)
1 parent b1de037 commit 8c21161

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

docs/en/sql-reference/20-sql-functions/05-datetime-functions/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ This section provides reference information for the datetime-related functions i
5757
- [LAST_DAY](last-day.md)
5858
- [NEXT_DAY](next-day.md)
5959
- [PREVIOUS_DAY](previous-day.md)
60+
- [TIMESTAMP_DIFF](timestamp-diff.md)
6061

6162
## Date Information Functions
6263

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: TIMESTAMP_DIFF
3+
---
4+
5+
import FunctionDescription from '@site/src/components/FunctionDescription';
6+
7+
<FunctionDescription description="Introduced or updated: v1.2.690"/>
8+
9+
Calculates the difference between two timestamps and returns the result as an INTERVAL.
10+
11+
## Syntax
12+
13+
```sql
14+
TIMESTAMP_DIFF(<timestamp1>, <timestamp2>)
15+
```
16+
17+
## Return Type
18+
19+
INTERVAL (formatted as `hours:minutes:seconds`).
20+
21+
## Examples
22+
23+
This example shows that the time difference between February 1, 2025, and January 1, 2025, is 744 hours, corresponding to 31 days:
24+
25+
```sql
26+
SELECT TIMESTAMP_DIFF('2025-02-01'::TIMESTAMP, '2025-01-01'::TIMESTAMP);
27+
28+
┌──────────────────────────────────────────────────────────────────┐
29+
│ timestamp_diff('2025-02-01'::TIMESTAMP, '2025-01-01'::TIMESTAMP) │
30+
├──────────────────────────────────────────────────────────────────┤
31+
744:00:00
32+
└──────────────────────────────────────────────────────────────────┘
33+
```

0 commit comments

Comments
 (0)