Converting Date-Times to ISO8601 in RStudio

Hi All,

I unknowingly uploaded data to RStudio with date-time columns in the mm-dd-yyyy format not knowing that RStudio's default is yyyy-mm-dd ( ISO8601). Is there anyway to convert the data i have in the dataframe without having to upload all of the data again?

library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union
the_date <- "05/09/2023"
dmy(the_date)
#> [1] "2023-09-05"

Created on 2023-09-05 with reprex v2.0.2

To use this with a data frame d having a column Date

d$Date <- dmy(d$Date)

Hi Technocrat,

Thank you once again for you input.

I tried the method you suggested but this is what I got. When I used to the head function to preview it the values were also changed to NA.

My data frame was case_study_1 and my column was started_at.

case_study_1$started_at <- mdy_hms(case_study_1$started_at)

The started_at values were returned as NA because they were, I think, in the format m/d/y H:M and you used the mdy_hms() function, which expects m/d/y H:M:S. There is a mdy_hm() function if your values do not include seconds.

lubridate::mdy_hms("5/9/2023 15:43")
[1] NA
Warning message:
All formats failed to parse. No formats found. 
> lubridate::mdy_hm("5/9/2023 15:43")
[1] "2023-05-09 15:43:00 UTC"
2 Likes

FJCC,

You were right! I changed it to mdy_hm and it worked! Thanks!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.