0

I have a very simple question

I have this value:

x <- 19630730

with class numeric. The as.Date() does not give me the expected result: 1963-07-30

what is the potential remedy to convert x to a date?

Thanks

msh855
  • 1,493
  • 1
  • 15
  • 36

1 Answers1

1

Convert to character first

x <- 19630730
as.Date(as.character(x), "%Y%m%d")
#[1] "1963-07-30"

If you use lubridate::ymd you don't need to convert to character.

lubridate::ymd(x)
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213