Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions content/en/ddsql_reference/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ Supported extraction units:
| `day` | `timestamp` / `interval` | day of the month |
| `dow` | `timestamp` | day of the week `1` (Monday) to `7` (Sunday) |
| `doy` | `timestamp` | day of the year (`1` - `366`) |
| `epoch` | `timestamp` / `interval` | seconds since 1970-01-01 00:00:00 UTC (for timestamps), or total number of seconds (for intervals) |
| `hour` | `timestamp` / `interval` | hour of the day (`0` - `23`) |
| `minute` | `timestamp` / `interval` | minute of the hour (`0` - `59`) |
| `second` | `timestamp` / `interval` | second of the minute (`0` - `59`) |
Expand All @@ -460,6 +461,27 @@ FROM
sales
{{< /code-block >}}

{{< code-block lang="sql" >}}
-- Get the Unix epoch of a timestamp
SELECT EXTRACT(epoch FROM TIMESTAMP '2021-01-01 00:00:00+00')
-- Returns: 1609459200
{{< /code-block >}}

{{< code-block lang="sql" >}}
-- Get the total seconds in an interval
SELECT EXTRACT(epoch FROM INTERVAL '1 day 2 hours')
-- Returns: 93600
{{< /code-block >}}

{{< code-block lang="sql" >}}
-- Calculate how many seconds ago each event occurred
SELECT
event_time,
EXTRACT(epoch FROM now()) - EXTRACT(epoch FROM event_time) AS seconds_ago
FROM
events
{{< /code-block >}}

### `TO_TIMESTAMP`

`TO_TIMESTAMP` has two forms:
Expand Down
Loading