Skip to content

as.POSIXct(): Support ISO 8601 date- & timestamps ('YYYY-MM-DDThh:mm:ss') #171

Description

@HenrikBengtsson

as.POSIXct() support RFC 3339 date- and timestamps without the 'T' specification ('YYYY-MM-DD hh:mm:ss');

> as.POSIXct("2025-06-28 08:53:33")
[1] "2025-06-28 08:53:33 CEST"

but not ISO 8601 date- and timestamps ('YYYY-MM-DDThh:mm:ss'):

> as.POSIXct("2025-06-28T08:53:33")
[1] "2025-06-28 CEST"

which silently drops the time component.

To parse the latter, we need to explicitly use strptime();

as.POSIXct(strptime("2025-06-28T08:53:33", "%Y-%m-%dT%H:%M:%S"))
[1] "2025-06-28 08:53:33 CEST"

From [1]: "Separating date and time parts with other characters such as space is not allowed in ISO 8601, but allowed in its profile RFC 3339."

Wish

  • Make as.POSIXct() recognize also ISO 8601 date- and timestamps.

References

[1] Section 'Combined date and time representations' in Wikipedia article 'ISO-8601', 2025-06-28 https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions