Pop Pop - 5 months ago 38
R Question

How to convert a date from a character string?

I have searched but I could not find out how to convert a date from a character string formatted as follows:

date <- "07-21-2015-09:30AM"

I wanted to use
, but I have not manage to. All I get is the following:

as.Date(date, format="%m-%d-%y-%hAM")

as.Date(dates, format="%m-%d-%y-%h")

Answer Source

If we need the 'date' and 'time', one option is as.POSIXct

 as.POSIXct(date, format='%m-%d-%Y-%I:%M%p')
 #[1] "2015-07-21 09:30:00 EDT"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download