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:
12:00:00
So, the specific question is: How to correctly parse this string to datetime?
(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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With