Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion docs/functions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function differs from the DataFusion built-in of the same name, if there is one.
- [Conditional Functions](scalar/conditional.md) (2)
- [String Functions](scalar/string.md) (17)
- [Binary String Functions](scalar/binary_string.md) (5)
- [Time and Date Functions](scalar/time_and_date.md) (28)
- [Time and Date Functions](scalar/time_and_date.md) (29)
- [Array Functions](scalar/array.md) (10)
- [Hashing Functions](scalar/hashing.md) (4)
- [Other Functions](scalar/other.md) (6)
Expand Down Expand Up @@ -77,6 +77,7 @@ function differs from the DataFusion built-in of the same name, if there is one.
- [datediff](scalar/time_and_date.md#datediff)
- [datepart](scalar/time_and_date.md#datepart)
- [dayname](scalar/time_and_date.md#dayname)
- [dayofweek](scalar/time_and_date.md#dayofweek)
- [elt](scalar/string.md#elt)
- [encode](scalar/binary_string.md#encode)
- [equal_null](scalar/other.md#equal_null)
Expand Down
26 changes: 26 additions & 0 deletions docs/functions/scalar/time_and_date.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Part of the [datafusion-spark function reference](../README.md).
- [datediff](#datediff)
- [datepart](#datepart)
- [dayname](#dayname)
- [dayofweek](#dayofweek)
- [from_utc_timestamp](#from_utc_timestamp)
- [hour](#hour)
- [last_day](#last_day)
Expand Down Expand Up @@ -284,6 +285,31 @@ Mon
NULL
```

## `dayofweek`

Returns the day of the week as an INT from 1 (Sunday) to 7 (Saturday). This differs from `weekday`, which counts from 0 (Monday) to 6 (Sunday), and from DataFusion's `date_part('dow', ...)`, which counts from 0 (Sunday) to 6 (Saturday). DataFusion has no built-in `dayofweek`. Strings are implicitly cast to DATE. A malformed string is an error, even with ANSI mode off where Spark returns NULL. A string that Spark reads as a partial date, such as '2009' or '2009-07', is also an error, where Spark uses the first day of that year or month. Timestamps are cast to DATE first, so the time of day is ignored. A timestamp with a time zone is converted in its own time zone, not the session time zone that Spark uses. Returns NULL if the input is NULL.

```sql
dayofweek(date)
```

### Arguments

- **date**: DATE, TIMESTAMP or string expression. NULL returns NULL.

### Example

```sql
> SELECT dayofweek('2009-07-30'::DATE);
5
> SELECT dayofweek('2009-07-30');
5
> SELECT dayofweek(arrow_cast('2024-01-07 23:59:59', 'Timestamp(Microsecond, None)'));
1
> SELECT dayofweek(NULL::DATE);
NULL
```

## `from_utc_timestamp`

Treats `ts` as a UTC wall-clock time and returns the wall-clock time in time zone `tz`. DataFusion has no built-in equivalent. A string `ts` is cast to a timestamp, so a string with an offset is first converted to UTC. The result has the same type as `ts`, including any time zone it carries. Returns NULL if either argument is NULL. `tz` accepts Spark's spellings: region IDs, offsets such as `+01:00`, `GMT+1`, `UTC+1:2` and `UT-010203`, Java short IDs such as `PST`, and legacy `SystemV/` IDs. An offset beyond 18 hours or an unknown zone is an error. Differences from Spark: `tz` is only parsed for rows where both arguments are non-NULL, so an invalid constant `tz` can return NULL where Spark raises an error; conversion is limited to Chrono's calendar range, which is narrower than the range Spark implements but covers Spark's documented range; and region rules from `chrono-tz` may differ after 2099, because it does not extrapolate later daylight saving time transitions.
Expand Down
Loading