Pop Pop - 23 days ago 7
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
as.Date
, but I have not manage to. All I get is the following:

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

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

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"