Skip to content

Extract day from underlying Date representation

Description

Returns the day of month starting from 1. The return value ranges from 1 to 31 (the last day of month differs across months).

Usage

<Expr>$dt$day()

Value

A polars expression

Examples

library("polars")

df <- pl$select(
  date = pl$date_range(
    as.Date("2020-12-25"),
    as.Date("2021-1-05"),
    interval = "1d"
  )
)
df$with_columns(
  pl$col("date")$dt$day()$alias("day")
)
#> shape: (12, 2)
#> ┌────────────┬─────┐
#> │ date       ┆ day │
#> │ ---        ┆ --- │
#> │ date       ┆ i8  │
#> ╞════════════╪═════╡
#> │ 2020-12-25 ┆ 25  │
#> │ 2020-12-26 ┆ 26  │
#> │ 2020-12-27 ┆ 27  │
#> │ 2020-12-28 ┆ 28  │
#> │ 2020-12-29 ┆ 29  │
#> │ …          ┆ …   │
#> │ 2021-01-01 ┆ 1   │
#> │ 2021-01-02 ┆ 2   │
#> │ 2021-01-03 ┆ 3   │
#> │ 2021-01-04 ┆ 4   │
#> │ 2021-01-05 ┆ 5   │
#> └────────────┴─────┘