R difference between dates with different formats -
what i'm trying calculate total days between 2 dates. if dates in "yyyy/mm/dd" format did way:
enddate <- "2012/02/01" startdate <- "1900/01/01" diffbewtweendates <- data.frame(date=c(enddate),start=c(startdate)) diffbewtweendates$date_diff <- as.date(as.character(diffbewtweendates$date), format="%y/%m/%d")- as.date(as.character(diffbewtweendates$start), format="%y/%m/%d") diffbewtweendates
and worked. i'm requested @ least enddate in format "fulldayname, daynumber of fullmonthname of fullyearnumber". "sunday, 1 of february of 2012".
as understand r manual, ...format="%a, %d of %b of %y"
doesn't work , can't figure out why.
thanks in advance idea.
perhaps got change locale english:
sys.setlocale("lc_time", "english") date <- "sunday, 1 of february of 2012" lubridate::guess_formats(date, orders = "dmy") # dmy # "%a, %d of %b of %y" as.date(date, guess_formats(date, orders = "dmy")) # [1] "2012-02-01"
anyway, can use lubridate's guess_formats
function guess formats many date strings.