I am trying to convert dates with ISOdate function, but I face 2 issues:
Here is the code I use:
firstDate <- as.Date("1910-01-01", "%Y-%m-%d")
todayDate <- Sys.Date() #Lets say its 2021-09-04
firstDatePOSIX <- as.POSIXlt(firstDate)
todayDatePOSIX <- as.POSIXlt(todayDate)
firstDateISO <- ISOdate(firstDatePOSIX$year + 1900, firstDatePOSIX$mon, firstDatePOSIX$mday)
todayDateISO <- ISOdate(todayDatePOSIX$year + 1900, todayDatePOSIX$mon, todayDatePOSIX$mday)
firstDateISO
returns NA
todayDateISO
returns "2021-08-04 12:00:00 GMT" instead of "2021-09-04 12:00:00 GMT"
My questions:
"1910-01-01 12:00:00 GMT"
with firstDateISO
?"2021-09-04 12:00:00 GMT"
with todayDateISO
?Any help much appreciated.
System used:
Use mon + 1
.
with(firstDatePOSIX, ISOdate(year + 1900, mon + 1, mday))
# [1] "1910-01-01 12:00:00 GMT"
with(todayDatePOSIX, ISOdate(year + 1900, mon + 1, mday))
# [1] "2021-09-04 12:00:00 GMT"