Skip to content

Data type representing a calendar date and time of day.

Source code

Description

The underlying representation of this type is a 64-bit signed integer. The integer indicates the number of time units since the Unix epoch (1970-01-01 00:00:00). The number can be negative to indicate datetimes before the epoch.

Usage

DataType_Datetime(time_unit = "us", time_zone = NULL)

Arguments

time_unit Unit of time. One of “ms”, “us” (default) or “ns”.
time_zone Time zone string, as defined in OlsonNames(). Setting timezone = “\*“ will match any timezone, which can be useful to select all Datetime columns containing a timezone.

Value

Datetime DataType

Examples

library("polars")

pl$Datetime("ns", "Pacific/Samoa")
#> DataType: Datetime(
#>     Nanoseconds,
#>     Some(
#>         "Pacific/Samoa",
#>     ),
#> )
df = pl$DataFrame(
  naive_time = as.POSIXct("1900-01-01"),
  zoned_time = as.POSIXct("1900-01-01", "UTC")
)
df
#> shape: (1, 2)
#> ┌─────────────────────┬─────────────────────────┐
#> │ naive_time          ┆ zoned_time              │
#> │ ---                 ┆ ---                     │
#> │ datetime[ms]        ┆ datetime[ms, UTC]       │
#> ╞═════════════════════╪═════════════════════════╡
#> │ 1900-01-01 00:00:00 ┆ 1900-01-01 00:00:00 UTC │
#> └─────────────────────┴─────────────────────────┘
df$select(pl$col(pl$Datetime("us", "*")))
#> shape: (0, 0)
#> ┌┐
#> ╞╡
#> └┘