This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new e19dd2d0b9 Add `to_local_time()` in function reference docs (#11401)
e19dd2d0b9 is described below
commit e19dd2d0b91f30b97fd68da894137987c1318b18
Author: Chunchun Ye <[email protected]>
AuthorDate: Thu Jul 11 11:21:51 2024 -0500
Add `to_local_time()` in function reference docs (#11401)
* chore: add document for `to_local_time()`
* chore: feedback
Co-authored-by: Andrew Lamb <[email protected]>
---------
Co-authored-by: Andrew Lamb <[email protected]>
---
docs/source/user-guide/sql/scalar_functions.md | 65 +++++++++++++++++++++++++-
1 file changed, 64 insertions(+), 1 deletion(-)
diff --git a/docs/source/user-guide/sql/scalar_functions.md
b/docs/source/user-guide/sql/scalar_functions.md
index d636726b45..d2e012cf40 100644
--- a/docs/source/user-guide/sql/scalar_functions.md
+++ b/docs/source/user-guide/sql/scalar_functions.md
@@ -1480,6 +1480,7 @@ contains(string, search_string)
- [make_date](#make_date)
- [to_char](#to_char)
- [to_date](#to_date)
+- [to_local_time](#to_local_time)
- [to_timestamp](#to_timestamp)
- [to_timestamp_millis](#to_timestamp_millis)
- [to_timestamp_micros](#to_timestamp_micros)
@@ -1710,7 +1711,7 @@ to_char(expression, format)
#### Example
```
-> > select to_char('2023-03-01'::date, '%d-%m-%Y');
+> select to_char('2023-03-01'::date, '%d-%m-%Y');
+----------------------------------------------+
| to_char(Utf8("2023-03-01"),Utf8("%d-%m-%Y")) |
+----------------------------------------------+
@@ -1771,6 +1772,68 @@ to_date(expression[, ..., format_n])
Additional examples can be found
[here](https://github.com/apache/datafusion/blob/main/datafusion-examples/examples/to_date.rs)
+### `to_local_time`
+
+Converts a timestamp with a timezone to a timestamp without a timezone (with
no offset or
+timezone information). This function handles daylight saving time changes.
+
+```
+to_local_time(expression)
+```
+
+#### Arguments
+
+- **expression**: Time expression to operate on. Can be a constant, column, or
function.
+
+#### Example
+
+```
+> SELECT to_local_time('2024-04-01T00:00:20Z'::timestamp);
++---------------------------------------------+
+| to_local_time(Utf8("2024-04-01T00:00:20Z")) |
++---------------------------------------------+
+| 2024-04-01T00:00:20 |
++---------------------------------------------+
+
+> SELECT to_local_time('2024-04-01T00:00:20Z'::timestamp AT TIME ZONE
'Europe/Brussels');
++---------------------------------------------+
+| to_local_time(Utf8("2024-04-01T00:00:20Z")) |
++---------------------------------------------+
+| 2024-04-01T00:00:20 |
++---------------------------------------------+
+
+> SELECT
+ time,
+ arrow_typeof(time) as type,
+ to_local_time(time) as to_local_time,
+ arrow_typeof(to_local_time(time)) as to_local_time_type
+FROM (
+ SELECT '2024-04-01T00:00:20Z'::timestamp AT TIME ZONE 'Europe/Brussels' AS
time
+);
++---------------------------+------------------------------------------------+---------------------+-----------------------------+
+| time | type |
to_local_time | to_local_time_type |
++---------------------------+------------------------------------------------+---------------------+-----------------------------+
+| 2024-04-01T00:00:20+02:00 | Timestamp(Nanosecond, Some("Europe/Brussels")) |
2024-04-01T00:00:20 | Timestamp(Nanosecond, None) |
++---------------------------+------------------------------------------------+---------------------+-----------------------------+
+
+# combine `to_local_time()` with `date_bin()` to bin on boundaries in the
timezone rather
+# than UTC boundaries
+
+> SELECT date_bin(interval '1 day',
to_local_time('2024-04-01T00:00:20Z'::timestamp AT TIME ZONE
'Europe/Brussels')) AS date_bin;
++---------------------+
+| date_bin |
++---------------------+
+| 2024-04-01T00:00:00 |
++---------------------+
+
+> SELECT date_bin(interval '1 day',
to_local_time('2024-04-01T00:00:20Z'::timestamp AT TIME ZONE
'Europe/Brussels')) AT TIME ZONE 'Europe/Brussels' AS date_bin_with_timezone;
++---------------------------+
+| date_bin_with_timezone |
++---------------------------+
+| 2024-04-01T00:00:00+02:00 |
++---------------------------+
+```
+
### `to_timestamp`
Converts a value to a timestamp (`YYYY-MM-DDT00:00:00Z`).
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]