Skip to content

Convert a String column into a Time column

Description

Convert a String column into a Time column

Usage

<Expr>$str$to_time(format = NULL, ..., strict = TRUE, cache = TRUE)

Arguments

format Format to use for conversion. Refer to the chrono crate documentation for the full specification. Example: “%Y-%m-%d %H:%M:%S”. If NULL (default), the format is inferred from the data. Notice that time zone %Z is not supported and will just ignore timezones. Numeric time zones like %z or %:z are supported.
These dots are for future extensions and must be empty.
strict If TRUE (default), raise an error if a single string cannot be parsed. If FALSE, produce a polars null.
cache Use a cache of unique, converted dates to apply the datetime conversion.

Value

A polars expression

See Also

  • \$str$strptime()

Examples

library("polars")

df <- pl$DataFrame(x = c("01:00", "02:00", "03:00"))

df$select(pl$col("x")$str$to_time("%H:%M"))
#> shape: (3, 1)
#> ┌──────────┐
#> │ x        │
#> │ ---      │
#> │ time     │
#> ╞══════════╡
#> │ 01:00:00 │
#> │ 02:00:00 │
#> │ 03:00:00 │
#> └──────────┘