Skip to content

Epoch

Source code

Description

Get the time passed since the Unix EPOCH in the give time unit.

Usage

<Expr>$dt$epoch(time_unit = "us")

Arguments

time_unit Time unit, one of “ns”, “us”, “ms”, “s” or “d”.

Value

Expr with datatype Int64

Examples

library("polars")

df = pl$DataFrame(date = pl$date_range(as.Date("2001-1-1"), as.Date("2001-1-3")))

df$with_columns(
  epoch_ns = pl$col("date")$dt$epoch(),
  epoch_s = pl$col("date")$dt$epoch(time_unit = "s")
)
#> shape: (3, 3)
#> ┌────────────┬─────────────────┬───────────┐
#> │ date       ┆ epoch_ns        ┆ epoch_s   │
#> │ ---        ┆ ---             ┆ ---       │
#> │ date       ┆ i64             ┆ i64       │
#> ╞════════════╪═════════════════╪═══════════╡
#> │ 2001-01-01 ┆ 978307200000000 ┆ 978307200 │
#> │ 2001-01-02 ┆ 978393600000000 ┆ 978393600 │
#> │ 2001-01-03 ┆ 978480000000000 ┆ 978480000 │
#> └────────────┴─────────────────┴───────────┘