Calculating Date Difference in Field Calculator?

120
1
Jump to solution
10-20-2022 09:39 AM
JonSwoveland
Occasional Contributor

OK, I solved this myself. Solution posted below.

I have a GeoEvent Definition with two date fields: Date_Entered & Date_Exited.  As you may suspect, these fields indicate  the date/time when an event (vehicle) enters and exists a GeoFence.

What I need to do is create a GeoEvent Service that calculates the difference betweens the two dates (in minutes), to determine how many minutes (n_minutes) the vehicle was inside the GeoFence.  If n_minutes > x, the feature representing the GeoFence will have one of its attributes updated to indicate it was "patrolled".

Using this tutorial I created a table in the geodatabase to store the patrol info for each GeoFence (vehicle id, geofence name, date enterered and date exited), and the required GeoEvent inputs / outputs and services to update this table.  This is all working.

Where I am stuck is using these date fields in a Field Calculator processor's expression.  I thought the Field Calculator automatically converts date fields to their milliseconds since epoch representation, so I tried:

((Date_Exited - Date_Entered) / 1000) / 60.    This results in a NULL value.

I then tried:

((toLong(Date_Exited) - toLong(Date_Entered)) / 1000) / 60. This also results in a NULL value.

Is there any way to do this kind of Date math?    

0 Kudos
1 Solution

Accepted Solutions
JonSwoveland
Occasional Contributor

It turns out there was nothing wrong with my expression. The reason I was getting a NULL value is that I failed to include the two date fields in the Field Mapper activity prior to the Field Calculator.  This wasn't just an oversight on my part. It was more of a lack of understand of how the plumbing works in GeoEvent Services.

View solution in original post

0 Kudos
1 Reply
JonSwoveland
Occasional Contributor

It turns out there was nothing wrong with my expression. The reason I was getting a NULL value is that I failed to include the two date fields in the Field Mapper activity prior to the Field Calculator.  This wasn't just an oversight on my part. It was more of a lack of understand of how the plumbing works in GeoEvent Services.

0 Kudos