Having problems parsing string to datetime

datetime, r

Solution

(1) try `strptime` instead of `strftime`; I'm not sure what `strftime` does, but maybe not what you think.

(2) I don't think "p.m." will work at all; you might need some judicious `gsub("p.m.","PM",...)` use.

strptime("28/10/2014 09:05:55 PM", format='%d/%m/%Y %I:%M:%S %p')
## [1] "2014-10-28 21:05:55 EDT"
strptime("28/10/2014 09:05:55 p.m.", format='%d/%m/%Y %I:%M:%S %p')
## NA

Problem

I'm having some problems parsing a string to datetime. This is what I'm doing ``` strftime("28/10/2014 09:05:55 p.m.", format='%d/%m/%Y %I:%M:%S %p') ##[1] "20/10/28 12:00:00 " ``` As you can see, three undesirable things are happening here: - The returned date is incorrect! - The time is always set to `12:00:00` - The returned value is a String, not a datetime (this is quite irrelevant... I can convert it to datetime later) So, the specific question is: How to correctly parse this string to datetime?

Original source