How to convert a "char" column to datetime column in large datasets


Good afternoon,

I am working with large datasets and in which one column is represented as char data type instead of a DateTime datatype. I trying it convert but I am unable to convert it.

Could you please suggest any suggestions for this problem? it would be very helpful for me

Thanks in advance

code which i am using right now
c_data$dt_1 <- lubridate::parse_date_time(c_data$started_at,"ymd HMS")

Output: 2027- 05- 20 20:10:03 but desired output is 2020-05-20 10:03

It's difficult to debug your code without seeing an example of c_data$started_at

parse_date_time() appears to be correctly parsing and formatting the time field; you should not expect it to remove the hour. To trim to minutes and seconds (which you seem to want to do), you must further process the datetime that lubridate is producing.

When facing difficult date/time parsing problems, I find it is best to set exact = TRUE and specify the exact formatting of the data/time string, warts and all. This is critical for weird, none-standard dates and times.

See the examples in the documentation:

1 Like

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.