Skip to content

Days

Source code

Description

Extract the days from a Duration type.

Usage

<Expr>$dt$total_days()

Value

Expr of i64

Examples

library("polars")

df = pl$DataFrame(
  date = pl$datetime_range(
    start = as.Date("2020-3-1"),
    end = as.Date("2020-5-1"),
    interval = "1mo1s"
  )
)
df$select(
  pl$col("date"),
  diff_days = pl$col("date")$diff()$dt$total_days()
)
#> shape: (2, 2)
#> ┌─────────────────────┬───────────┐
#> │ date                ┆ diff_days │
#> │ ---                 ┆ ---       │
#> │ datetime[μs]        ┆ i64       │
#> ╞═════════════════════╪═══════════╡
#> │ 2020-03-01 00:00:00 ┆ null      │
#> │ 2020-04-01 00:00:01 ┆ 31        │
#> └─────────────────────┴───────────┘