So I'm trying to read a date from a long date string.
I'm not real sure what I'm doing wrong here.
lines = "Friday, November 30, 2018, 8:00 AM" as.POSIXlt(lines, format = "%A, %B %m, %Y, %I, %p")
Try this:
# example dates lines = c("Friday, November 30, 2018, 8:00 AM", "Friday, November 30, 2018, 8:00 PM") as.POSIXlt(lines, format = "%A, %B %d, %Y, %I:%M %p") # "2018-11-30 08:00:00 GMT" # "2018-11-30 20:00:00 GMT"
Using lubridate package:
lubridate
parse_date_time(lines, "%A, %B %d, %Y, %I:%M %p")
or
parse_date_time(lines, "%A, %B %d, %Y, %H:%M %p") ## "2018-11-30 08:00:00 UTC"
or even simpler format :
parse_date_time(lines, "abdyHMp")
Copyright © 2021 Jogjafile Inc.
Try this: