This isn't duplicate. I already referred these posts 1,2,3
I have a dataframe like below:
t_df <- data.frame("SN" = c("AabcC123","ABC123","ABC123","MNO098","MNO098","MNO098"),
"code" = c("ABC1111","DEF222","GHI133","","MNO1123","MNO567"),
"d_time" = c("21/12/2012 12:12","30/06/2019 11:11","20/02/2027 10:10","22/11/2327 09:09:11","5/2/1927 08:08:12",""))
t_df <- data.frame(lapply(t_df, as.character), stringsAsFactors=FALSE)
While I read the csv file, all my dates are of character
type.
So when I try to sort the dataframe, it only works based on first characters.
I would like to convert this to Datetime
format.
Though I tried the below options based on other posts that I linked above, nothing helped. It returns NA
as_datetime(t_df$d_time, "%d/%m/%Y %H:%M:%S")
as.POSIXct(t_df$d_time,format="%d/%m/%Y %H:%M:%S")
dmy_hms(t_df$d_time)
Can you help me convert the datatype to datetime
?