My goal is to take a character vector of dates formatted as YYYY-MM-DD HH-MM-SS and get just MM-YYYY. Here is my code:
EndDate <- c("2020-10-01 10:37:38", "2020-11-01 10:42:48") #character string with hms
EndDate <- as.Date(ymd_hms(EndDate)) #wrap ymd_hms in as.Date to strip hms
It works up to this point, but here is where it falls apart.
EndDate <- format(EndDate, "%m-%Y") #returns a character vector
EndDate <- as.Date(EndDate, format = "%m-%Y") #returns a date vector of NAs
I'm not sure what is causing the NAs or what I'm doing wrong.