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
I like
strptime
for this:And in the case that you needed to see the date in the same format as entered, you can call the related
strftime
. It doesn't change the internal storage of the variable, rather it changes the format only.If we need the 'date' and 'time', one option is
as.POSIXct
You can also use the lubridate package like this: