04pallav
9/13/2017 - 9:28 PM

Convert string to datetime lubridate

Convert string to datetime lubridate

A date + time is represented in R as an object of class POSIXct. A date is represented as an object of class Date.

mdy("09/14/2014")
ymd_hms("2014-09-24 15:23:10")

as.Date(df$order_datetime)


parse_date_time of lubridate package can help format multiple date formats in one go.

df1$order_datetime= parse_date_time(df1$order_datetime, c('%m%d%y %H:%M:%S', '%Y-%m-%d %H:%M:%S','%Y-%m-%d'))
### Needs to be in the exact same format or will give error ## this is good as dates and months are not confused