Skip to content

Convert a String column into a Time column

Source code

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.
Not used.
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.

Format

Format to use for conversion. Refer to the chrono crate documentation for the full specification. Example: “%H:%M:%S”. If NULL (default), the format is inferred from the data.

Value

Expr of Time type

See Also

  • \$str$strptime()

Examples

library(polars)

s = as_polars_series(c("01:00", "02:00", "03:00"))

s$str$to_time("%H:%M")
#> polars Series: shape: (3,)
#> Series: '' [time]
#> [
#>  01:00:00
#>  02:00:00
#>  03:00:00
#> ]