Skip to content

Extract month from underlying Date representation

Description

Returns the month number between 1 and 12.

Usage

<Expr>$dt$month()

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(
  date = as.Date(c("2001-01-01", "2001-06-30", "2001-12-27"))
)
df$with_columns(
  month = pl$col("date")$dt$month()
)
#> shape: (3, 2)
#> ┌────────────┬───────┐
#> │ date       ┆ month │
#> │ ---        ┆ ---   │
#> │ date       ┆ i8    │
#> ╞════════════╪═══════╡
#> │ 2001-01-01 ┆ 1     │
#> │ 2001-06-30 ┆ 6     │
#> │ 2001-12-27 ┆ 12    │
#> └────────────┴───────┘