Convert a Date/Time/Datetime/Duration column into a String column with the given format
Description
Similar to $cast(pl$String)
, but
this method allows you to customize the formatting of the resulting
string. This is an alias for $dt$to_string()
.
Usage
<Expr>$dt$strftime(format)
Arguments
format
|
Single string of format to use, or NULL . NULL
will be treated as “iso” . Available formats depend on the
column data type:
|
Value
A polars expression
Examples
library("polars")
pl$DataFrame(
datetime = c(as.POSIXct(c("2021-01-02 00:00:00", "2021-01-03 00:00:00")))
)$
with_columns(
datetime_string = pl$col("datetime")$dt$strftime("%Y/%m/%d %H:%M:%S")
)
#> shape: (2, 2)
#> ┌─────────────────────┬─────────────────────┐
#> │ datetime ┆ datetime_string │
#> │ --- ┆ --- │
#> │ datetime[ms] ┆ str │
#> ╞═════════════════════╪═════════════════════╡
#> │ 2021-01-02 00:00:00 ┆ 2021/01/02 00:00:00 │
#> │ 2021-01-03 00:00:00 ┆ 2021/01/03 00:00:00 │
#> └─────────────────────┴─────────────────────┘