I am wanting to convert date-times stored as characters to date-time objects. However if a date time includes midnight then the resulting datetime object excludes the time c
lubridate::as_datetime() is more flexible, accepting both dates (interpreted as 00:00:00) and datetimes.
example.dates <- c("2011-11-02", "2011-11-02 00:31:00","2011-11-02 00:00:00","2011-11-02 00:20:22")
library(lubridate)
ymd_hms(example.dates)
#> Warning: 1 failed to parse.
#> [1] NA "2011-11-02 00:31:00 UTC"
#> [3] "2011-11-02 00:00:00 UTC" "2011-11-02 00:20:22 UTC"
as_datetime(example.dates)
#> [1] "2011-11-02 00:00:00 UTC" "2011-11-02 00:31:00 UTC"
#> [3] "2011-11-02 00:00:00 UTC" "2011-11-02 00:20:22 UTC"