Need to convert a string to a date in GeoEvent

1480
2
Jump to solution
07-15-2019 02:19 PM
ISP_graynic
Occasional Contributor II

I have a feature layer that has the date/time in two separate string fields labeled "Date" and "Time".  I need to convert these into a date field using GeoEvent.  I created a second feature service that has a DateTime field that is a date field however I am having trouble getting GeoEvent to copy the string date over into the second feature layer as a date.  Any help is appreciated.

0 Kudos
1 Solution

Accepted Solutions
ISP_graynic
Occasional Contributor II

Thanks Adam!  I just figured out another way to do it in GeoEvent.  First, I used a Field Calculator in GeoEvent to combine the date and time fields (Date + ' ' + Time) and output the result as a string.  Then I used another Field Calculator to replace all the dashes in the date field (replaceAll(Date,'-','/')).  I created a new date field while also creating a new definition that had a date/time field.  Finally I used Field Mapper to map this newly created date/time field from the new definition in a new feature layer.  

View solution in original post

2 Replies
AdamRepsher
Occasional Contributor III

Nicholas Gray,

Have you tried calculating the two string fields (date and time) into one ISO 8601 compliant string into a new field?  I don't know how your original date and time strings look.  You may have to do a bunch of substring() function calculations to pull out pieces of everything, like Year, Month, Day, Hour, Minute, Second, Millisecond and put them into their own string fields - and then calculate them all together into one compliant "DateTime" string.  Depending what time zone your data stream sends it's date and time in, you will probably have to add it to the string.

For example, if DateField value = 07/18/2019 and TimeField value = 1630 , you would have to pull out all of the elements of both date and time given and place them into new string fields using Substring Field Calculations in GeoEvent(In this case I am assuming that your date data always has 2 characters in Month and Day with leading zeros)

Year: 2019 - calculated into "year" field with expression substring(DateField,6,-1)

Month: 07 - from substring(DateField,0,2)

Day: 18 - from substring(DateField,3,5)

Hour: 16 - from substring(TimeField,0,2)

Minute: 30 - from substring(TimeField,2,-1)

Then the calculation to concatenate everything back into another string field ISODate:

Expression:  Year + '-' + Month + '-' + Day + 'T' + Hour + ':' + Minute + ':00+00:00'

Result:  2019-07-18T16:30:00+00:00

(This is assuming that the feed is sending date/time in GMT  - change the +00:00 to whatever your time zone is if the time is local - mine would be -04:00)

That would be the first step.

You could then just use a "Push JSON to an External Websocket" output to push the ISODate string into a "Receive JSON on a Websocket" input, with the field definition for the "DateTime" field set to Type: Date. 

From here, you could process anything else you need and then push to a Feature Service with a DateTime field defined as Date.

A very good Blog Post to view too.

--Adam

ISP_graynic
Occasional Contributor II

Thanks Adam!  I just figured out another way to do it in GeoEvent.  First, I used a Field Calculator in GeoEvent to combine the date and time fields (Date + ' ' + Time) and output the result as a string.  Then I used another Field Calculator to replace all the dashes in the date field (replaceAll(Date,'-','/')).  I created a new date field while also creating a new definition that had a date/time field.  Finally I used Field Mapper to map this newly created date/time field from the new definition in a new feature layer.