Skip to content

Instantly share code, notes, and snippets.

@scw
Last active October 21, 2015 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scw/f42d22a09e6e87d0d85f to your computer and use it in GitHub Desktop.
Save scw/f42d22a09e6e87d0d85f to your computer and use it in GitHub Desktop.
Convert an FGDB sourced datetime column to a POSIXct type in R
library('arcgisbinding')
arc.check_product()
# a FGDB source with a column 'datetime' containing our datetime field
d <- arc.open('a/fgdb/source')
df <- arc.select(d, 'datetime')
# convert from 1899-12-30 00:00 to UNIX Epoch, in seconds
as.unix.epoch <- (df$datetime[1]-25569)*86400
# convert to POSIXct object, albeit with invalid TZ
ct <- as.POSIXct(as.unix.epoch, origin="1970-1-1", tz="GMT")
# fix the TZ
fmt <- paste("%Y-%m-%d %H:%M:%S%z ", Sys.timezone())
ct.with.tz <- as.POSIXct(format(ct, fmt), usetz=TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment