[R] Unexpected date format coercion

Uwe Ligges
Thu, 01 Jul 2021 08:21:06 -0000

On 01.07.2021 10:06, Jeremie Juste wrote:
> Hello,
>
> I have been surprised when converting a character string to a date with the
following
> format,
>
> in R 4.1.0 (linux debian 10)
>
> as.Date("20-12-2020","%Y-%m-%d")
> [1] "20-12-20"
>
> in R 4.0.5 (window 10)
>
> as.Date("20-12-2020","%Y-%m-%d")
> [1] "0020-12-20"

Yes, it is rather strange to specify "2020" as the day and
"20" as the
4digits year, so different implementations may print the year in 2 or 4
digits. What you want is actually

as.Date("20-12-2020","%d-%m-%Y")


Best,
Uwe Ligges






>
>
> Here I was expecting a blunt and sharp NA, am I missing something?
>
> Best regards,
> Jeremie
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide