Using lubridate in R
16:20 14 Apr 2026

I have character data in an iso8601 format that I would like to convert to a datetime variable:

I tried the following:

datetime_str <- "2026-04-02T02:16-04:00"

dt <- ymd_hms(datetime_str)

dt <- ymd_hm(datetime_str)

class(dt)

print(dt)

R returns "All formats failed to parse. No formats found."

dt is NA

If I add seconds to the datetime_str, it works properly. Unfortunately, my datetime input records do not include seconds.

How do I fix this?

r datetime lubridate iso8601