3

I have a data set where one of the columns is sales date. Don't know why, but R converts it to numeric why performing any operation. I would like to convert it back to POSIXct date format in R. To do the same, I am using below code, but getting an unexpected result

 x= as.Date(1448208000, origin = "1970-01-01")
[1] "3967028-10-31"
 x= as.POSIXct(x,"%Y-%m-%d")

I am not good with dates format in R and would appreciate any kind of help in this regard.

zx8754
  • 52,746
  • 12
  • 114
  • 209
honey
  • 89
  • 2
  • 8

1 Answers1

3

1448208000 is the number of seconds since the unix epoch, and is the numeric representation of a POSIX object. To convert it back to POSIXct you want

as.POSIXct(1448208000, origin = "1970-01-01")

You'll also probably want to ensure the timezone is correct too; see the difference between these two commands

as.POSIXct(1448208000, origin = "1970-01-01", tz = "UTC")
# [1] "2015-11-22 16:00:00 UTC"

as.POSIXct(1448208000, origin = "1970-01-01", tz = "Australia/Melbourne")
# [1] "2015-11-23 03:00:00 AEDT"
SymbolixAU
  • 25,502
  • 4
  • 67
  • 139