From f9ef488aecca9a445a5110079fb2f295c80a8850 Mon Sep 17 00:00:00 2001 From: Bruce Ritchie Date: Wed, 22 May 2024 13:50:09 -0400 Subject: [PATCH] Add to_unixtime function to scalar functions doc (#10620) --- .../source/user-guide/sql/scalar_functions.md | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/docs/source/user-guide/sql/scalar_functions.md b/docs/source/user-guide/sql/scalar_functions.md index f0feb9ec2183..625e0d95b57e 100644 --- a/docs/source/user-guide/sql/scalar_functions.md +++ b/docs/source/user-guide/sql/scalar_functions.md @@ -1464,6 +1464,7 @@ position(substr in origstr) - [to_timestamp_seconds](#to_timestamp_seconds) - [to_timestamp_nanos](#to_timestamp_nanos) - [from_unixtime](#from_unixtime) +- [to_unixtime](#to_unixtime) ### `now` @@ -1964,6 +1965,41 @@ from_unixtime(expression) - **expression**: Expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators. +### `to_unixtime` + +Converts a value to seconds since the unix epoch (`1970-01-01T00:00:00Z`). +Supports strings, dates, timestamps and double types as input. +Strings are parsed as RFC3339 (e.g. '2023-07-20T05:44:00') if no [Chrono formats] are provided. + +``` +to_unixtime(expression[, ..., format_n]) +``` + +#### Arguments + +- **expression**: Expression to operate on. + Can be a constant, column, or function, and any combination of arithmetic operators. +- **format_n**: Optional [Chrono format] strings to use to parse the expression. Formats will be tried in the order + they appear with the first successful one being returned. If none of the formats successfully parse the expression + an error will be returned. + +#### Example + +``` +> select to_unixtime('2020-09-08T12:00:00+00:00'); ++------------------------------------------------+ +| to_unixtime(Utf8("2020-09-08T12:00:00+00:00")) | ++------------------------------------------------+ +| 1599566400 | ++------------------------------------------------+ +> select to_unixtime('01-14-2023 01:01:30+05:30', '%q', '%d-%m-%Y %H/%M/%S', '%+', '%m-%d-%Y %H:%M:%S%#z'); ++-----------------------------------------------------------------------------------------------------------------------------+ +| to_unixtime(Utf8("01-14-2023 01:01:30+05:30"),Utf8("%q"),Utf8("%d-%m-%Y %H/%M/%S"),Utf8("%+"),Utf8("%m-%d-%Y %H:%M:%S%#z")) | ++-----------------------------------------------------------------------------------------------------------------------------+ +| 1673638290 | ++-----------------------------------------------------------------------------------------------------------------------------+ +``` + ## Array Functions - [array_append](#array_append)