0

I have a date 2008-01-01 and its class in R is Date. When I try to save these dates in a table that has other values it change the format of date to a number like 13879! In addition, I cannot have 20080101! I try to change the class of date to character but it gave me 2008-01-01 and made the class of my table to character! Is there any way to change 2008-01-01 to 20080101 as a number?

hamideh
  • 31
  • 5
  • 1
    I'm pretty sure [@GSee](http://stackoverflow.com/users/967840/gsee)'s answer is what you need, but you really should consider posting a [minimal, reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) in the future. – hrbrmstr Mar 22 '14 at 22:41

1 Answers1

2

You can use format to covert it to a character string "20080101", then convert that to an integer (or numeric)

myDate <- as.Date("2008-01-01")
as.integer(format(myDate, "%Y%m%d"))
GSee
  • 48,880
  • 13
  • 125
  • 145