Skip to content

Extract microseconds from underlying Datetime representation.

Source code

Description

Applies to Datetime columns.

Usage

<Expr>$dt$microsecond()

Value

Expr of data type Int32

Examples

library(polars)

df = pl$DataFrame(
  datetime = as.POSIXct(
    c(
      "1978-01-01 01:01:01",
      "2024-10-13 05:30:14.500",
      "2065-01-01 10:20:30.06"
    ),
    "UTC"
  )
)

df$with_columns(
  microsecond = pl$col("datetime")$dt$microsecond()
)
#> shape: (3, 2)
#> ┌─────────────────────────────┬─────────────┐
#> │ datetime                    ┆ microsecond │
#> │ ---                         ┆ ---         │
#> │ datetime[ms, UTC]           ┆ i32         │
#> ╞═════════════════════════════╪═════════════╡
#> │ 1978-01-01 01:01:01 UTC     ┆ 0           │
#> │ 2024-10-13 05:30:14.500 UTC ┆ 500000      │
#> │ 2065-01-01 10:20:30.060 UTC ┆ 60000       │
#> └─────────────────────────────┴─────────────┘