Currently, I have date data stored in the column of a large data.table table. The date data look something like:
dt1 <- data.table(Person = seq(6), Date = ymd_hms(c("2007-1-1 12:31:25 PST", "2007-1-3 09:31:25 PST", "2007-1-9 15:31:22 PST", "2007-1-17 21:41:23 PST", "2007-1-30 02:04:22 PST", "2007-2-2 02:07:12 PST")))
> dt1
Person Date
1: 1 2007-01-01 12:31:25
2: 2 2007-01-03 09:31:25
3: 3 2007-01-09 15:31:22
4: 4 2007-01-17 21:41:23
5: 5 2007-01-30 02:04:22
6: 6 2007-02-02 02:07:12
ymd_hms() is a function in the package lubridate
. Now, when I convert the dates to numeric as so, I get:
dt1[,Date:=as.numeric(Date)]
> dt1
Person Date
1: 1 1167654685
2: 2 1167816685
3: 3 1168356682
4: 4 1169070083
5: 5 1170122662
6: 6 1170382032
After this, I have tried various methods but have been unable to convert the dates back to the original format. Would anyone know of a simple function? Thank you!
dt1[, as.POSIXct(Date, origin="1970-01-01", tz="UTC")]
– GSee