to_epoch()
Convert a timestamptz to a Unix epoch time
Since 1.16.0
Given a timestamptz, return the number of seconds since January 1, 1970 (the Unix epoch).
Samples
Section titled “Samples”Convert a date to a Unix epoch time:
SELECT to_epoch('2021-01-01 00:00:00+03'::timestamptz);The output looks like this:
to_epoch------------ 1609448400Arguments
Section titled “Arguments”The syntax is:
SELECT to_epoch('<date>');| Name | Type | Default | Required | Description |
|---|---|---|---|---|
date | TIMESTAMPTZ | - | ✔ | Timestamp to use to calculate epoch |
Returns
Section titled “Returns”| Column | Type | Description |
|---|---|---|
to_epoch | DOUBLE PRECISION | The number of seconds since January 1, 1970 (Unix epoch) |