how to transfer as.Date in R to Date in ArcGIS

197
3
05-16-2019 04:38 AM
RamB
by
Occasional Contributor II

Hi,

how do I convert a as.Date of R to a Date in ArcGIS? The field is a date in the r data.frame, but when it is opened in arcgis, it is a character/ string type. 

thank you.

Tags (1)
Reply
0 Kudos
3 Replies
Egge-JanPollé1
MVP Regular Contributor

Hi Srirama Bhamidipati‌,

You may want to use Python to convert the string in ArcGIS to a datetime object.

Does this Stack Overflow discussion python - Converting string into datetime - Stack Overflow answer your question?

datetime.strptime is the main routine for parsing strings into datetimes. It can handle all sorts of formats, with the format determined by a format string you give it

HTH,

Egge-Jan

Reply
0 Kudos
RamB
by
Occasional Contributor II

Thank you, but my all workflow is in R. So Not sure what you mean ?

Reply
0 Kudos
ShaunWalbridge
Esri Regular Contributor

Can you provide a code sample? I'm not able to reproduce this, as.Date and POSIX date objects are being converted to a Date field in an output geodatabase in my tests. Here's an example:

library(arcgisbinding)
arc.check_product()

Sys.setenv(TZ="UTC")

df <- data.frame(
a = c(0, 1, NA, -Inf, Inf),
b = c("a", "b", NA, "c", ""),
c = c(as.Date("2001-01-01"), NA, -99, 0, 1),
d = c(as.POSIXct("2001-01-01"), NA, -99, 0, 1),


arc.write("date.gdb/with_date")

With that, I get two date columns, "c" and "d", which contain values I would expect.

Reply
0 Kudos