This is a strange rule of century inference in the y
year mask.
In documentation we have the following conversion information of dates with two digits:
%y
Year without century (00-99). At the entrance, values between 00 and 68 are
prefixed by 20 and values between 69 and 99 by 19 - this is the behavior
specified by the POSIX 2004 and 2008 standards, but they [the authors of the
also say that "it is
expected that in a future version the standard century inferred from a year of two
digits will change ".
In this way, it is up to the application to manipulate the century according to its own rules, for example, you can fix which dates in the future should be converted to the 20th century:
data_de_nascimento = c("16/03/66", "11/06/87", "21/11/75", "05/09/70",
"15/08/70", "15/08/70")
d <- as.Date(data_de_nascimento, "%d/%m/%y" )
data_de_nascimento_format <- as.Date(
ifelse(d > Sys.Date(), format(d, "19%y-%m-%d"), format(d)))
You can replace Sys.Date()
with a specific cut-off date. For example, if you want dates between 00 and 10 to be inferred for the 21st century use "2010-12-31"
. In this case, 16/03/10
will be interpreted as "2010-03-16"
, however 16/03/11
will be interpreted as "1911-03-16"
.
Reference: SOen - Add year to century without date, and