Search code examples
rlubridate

convert datetime string with month abbreviation to datetime object using lubridate


How can I convert this string to datetime using lubridate? It has abbreviation of month. The desired output is 12/1/2020 9:19:00 AM

library(lubridate)

datetime_string = "01-DEC-2020 09:19 AM"


Solution

  • Try this:

    datetime_string = "01-DEC-2020 09:19 AM"
    timeValue <- lubridate::dmy_hm(datetime_string) 
    
    format(timeValue, "%m/%d/%Y %H:%M:%S %p")
    # "12/01/2020 09:19:00 AM"