Skip to content

Roll backward to the first day of the month

Description

For datetimes, the time of day is preserved.

Usage

<Expr>$dt$month_start()

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(date = as.Date(c("2000-01-23", "2001-01-12", "2002-01-01")))

df$with_columns(
  month_start = pl$col("date")$dt$month_start()
)
#> shape: (3, 2)
#> ┌────────────┬─────────────┐
#> │ date       ┆ month_start │
#> │ ---        ┆ ---         │
#> │ date       ┆ date        │
#> ╞════════════╪═════════════╡
#> │ 2000-01-23 ┆ 2000-01-01  │
#> │ 2001-01-12 ┆ 2001-01-01  │
#> │ 2002-01-01 ┆ 2002-01-01  │
#> └────────────┴─────────────┘