Skip to content

Commit c77ac73

Browse files
appletreeisyellowalamb
authored andcommitted
Add to_local_time() in function reference docs (apache#11401)
* chore: add document for `to_local_time()` * chore: feedback Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org> --------- Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
1 parent bf8142a commit c77ac73

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

docs/source/user-guide/sql/scalar_functions.md

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,7 @@ contains(string, search_string)
14801480
- [make_date](#make_date)
14811481
- [to_char](#to_char)
14821482
- [to_date](#to_date)
1483+
- [to_local_time](#to_local_time)
14831484
- [to_timestamp](#to_timestamp)
14841485
- [to_timestamp_millis](#to_timestamp_millis)
14851486
- [to_timestamp_micros](#to_timestamp_micros)
@@ -1710,7 +1711,7 @@ to_char(expression, format)
17101711
#### Example
17111712

17121713
```
1713-
> > select to_char('2023-03-01'::date, '%d-%m-%Y');
1714+
> select to_char('2023-03-01'::date, '%d-%m-%Y');
17141715
+----------------------------------------------+
17151716
| to_char(Utf8("2023-03-01"),Utf8("%d-%m-%Y")) |
17161717
+----------------------------------------------+
@@ -1771,6 +1772,68 @@ to_date(expression[, ..., format_n])
17711772

17721773
Additional examples can be found [here](https://github.com/apache/datafusion/blob/main/datafusion-examples/examples/to_date.rs)
17731774

1775+
### `to_local_time`
1776+
1777+
Converts a timestamp with a timezone to a timestamp without a timezone (with no offset or
1778+
timezone information). This function handles daylight saving time changes.
1779+
1780+
```
1781+
to_local_time(expression)
1782+
```
1783+
1784+
#### Arguments
1785+
1786+
- **expression**: Time expression to operate on. Can be a constant, column, or function.
1787+
1788+
#### Example
1789+
1790+
```
1791+
> SELECT to_local_time('2024-04-01T00:00:20Z'::timestamp);
1792+
+---------------------------------------------+
1793+
| to_local_time(Utf8("2024-04-01T00:00:20Z")) |
1794+
+---------------------------------------------+
1795+
| 2024-04-01T00:00:20 |
1796+
+---------------------------------------------+
1797+
1798+
> SELECT to_local_time('2024-04-01T00:00:20Z'::timestamp AT TIME ZONE 'Europe/Brussels');
1799+
+---------------------------------------------+
1800+
| to_local_time(Utf8("2024-04-01T00:00:20Z")) |
1801+
+---------------------------------------------+
1802+
| 2024-04-01T00:00:20 |
1803+
+---------------------------------------------+
1804+
1805+
> SELECT
1806+
time,
1807+
arrow_typeof(time) as type,
1808+
to_local_time(time) as to_local_time,
1809+
arrow_typeof(to_local_time(time)) as to_local_time_type
1810+
FROM (
1811+
SELECT '2024-04-01T00:00:20Z'::timestamp AT TIME ZONE 'Europe/Brussels' AS time
1812+
);
1813+
+---------------------------+------------------------------------------------+---------------------+-----------------------------+
1814+
| time | type | to_local_time | to_local_time_type |
1815+
+---------------------------+------------------------------------------------+---------------------+-----------------------------+
1816+
| 2024-04-01T00:00:20+02:00 | Timestamp(Nanosecond, Some("Europe/Brussels")) | 2024-04-01T00:00:20 | Timestamp(Nanosecond, None) |
1817+
+---------------------------+------------------------------------------------+---------------------+-----------------------------+
1818+
1819+
# combine `to_local_time()` with `date_bin()` to bin on boundaries in the timezone rather
1820+
# than UTC boundaries
1821+
1822+
> SELECT date_bin(interval '1 day', to_local_time('2024-04-01T00:00:20Z'::timestamp AT TIME ZONE 'Europe/Brussels')) AS date_bin;
1823+
+---------------------+
1824+
| date_bin |
1825+
+---------------------+
1826+
| 2024-04-01T00:00:00 |
1827+
+---------------------+
1828+
1829+
> 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;
1830+
+---------------------------+
1831+
| date_bin_with_timezone |
1832+
+---------------------------+
1833+
| 2024-04-01T00:00:00+02:00 |
1834+
+---------------------------+
1835+
```
1836+
17741837
### `to_timestamp`
17751838

17761839
Converts a value to a timestamp (`YYYY-MM-DDT00:00:00Z`).

0 commit comments

Comments
 (0)