Skip to content
Prev 244572 / 398502 Next

Remove 100 years from a date object

On Fri, Dec 10, 2010 at 10:27 AM, Daniel Brewer <daniel.brewer at icr.ac.uk> wrote:
The easiest is just to use chron dates since it uses a cut.off of 30
by default.   That is, if yy is less than that then 2000+yy is used
and if greater than that then 1900+yy is used.

Thus try this:

library(chron)
d <- "27.02.37"
as.Date(dates(d, format = "d.m.y")) # "1937-02-27"
as.Date(d, format = "%d.%m.%y")  # "2037-02-27"


Also if that is not good enough and you want a different value for the
cut.off then note that the default in chron is to use the year.expand
function to expand two digit dates but you can change that via
something like this:

options(chron.year.expand = function(..., cut.off = 25)
year.expand(..., cut.off = cut.off))