tidyverse / lubridate

Make working with dates in R just that little bit easier
https://lubridate.tidyverse.org
GNU General Public License v3.0
728 stars 207 forks source link

Origin = "1900-01-01" converts to wrong date #1053

Closed UgyenNorbu closed 1 year ago

UgyenNorbu commented 2 years ago

When converting an integer to a date object using as_date() function from Lubridate, the output date is erroneous. For eg. 44713 should give 2022-06-01 (yyyy-mm-dd), but instead it outputs 2022-06-03.

library(lubridate)

as_date(44713, origin = "1900-01-01")

#> [1] "2022-06-03"

Would appreciate if this error can be resolved at the earliest opportunity.

vspinu commented 1 year ago

Your calculation is incorrect

> as.Date(44713, origin = "1900-01-01")
[1] "2022-06-03"
> ymd("2022-06-03") - ymd("1900-01-01")
Time difference of 44713 days

https://www.timeanddate.com/date/durationresult.html?d1=03&m1=06&y1=2022&d2=01&m2=01&y2=1900