0

Using this it gives the date time format to the specific column

 df[,":="(date = as.numeric(as.POSIXct(date , "%Y-%m-%d %H:%M:%S"))]

How is it possible to convert a date column to a epoch/unix date column like this it can be for one value

as.numeric(as.POSIXct("2013-09-16 2:13:46 EST"))
Nathalie
  • 1,228
  • 7
  • 20
  • Use `tz = "GMT", origin="1970-01-01"`. If your timezone is different, add/subtract the appropriate number of seconds to the result above. Or adjust the number of hours to the date/time before converting to numeric: `as.integer(as.POSIXct("2013-09-16 7:13:46", tz = "GMT"))`. Argument `origin` is optional, since R's default is `"1970-01-01"`. – Rui Barradas Jan 06 '20 at 00:06
  • @RuiBarradas-ReinstateMonic how can I make it for the whole column df[,":="(date = as.numeric(as.POSIXct(date , "%Y-%m-%d %H:%M:%S"))] ? – Nathalie Jan 06 '20 at 00:13
  • `df[, date := as.numeric(as.POSIXct(date , "%Y-%m-%d %H:%M:%S"))]`. Your date already is in the default format, just `df[, date := as.numeric(as.POSIXct(date))]` will do the same and is simpler. – Rui Barradas Jan 06 '20 at 00:16

0 Answers0