Skip to main content
Question

Calculate the time difference between two features in a non-spatial dataset


Hi all,

 

 

I have a dataset (from MS Access) that has fields as follows:

 

 

Site Name       Sample Date/Time     

 

A                        08/16/2014 08:00

 

A                        08/17/2014 14:00

 

A                        08/25/2014 12:30

 

B                       07/04/2014 11:00

 

B                       08/04/2014 11:00

 

B                       09/04/2014 11:00

 

 

I want to be able to calculate the time in days, hours or minutes between each feature and the preceeding one (i.e. how long between each sample at each site) where the site name is the same.  The output would then look like this...

 

 

Site Name       Sample Date/Time    TimeSinceLast (hours)

 

A                        08/16/2014 08:00       -

 

A                        08/17/2014 14:00       30

 

A                        08/25/2014 12:30       190.5

 

B                       07/04/2014 11:00        -

 

B                       08/04/2014 11:00        744

 

B                       09/04/2014 11:00        744

 

 

Any ideas greatly appreciated.  I'm very new to FME, just done the Basic Desktop Webinar.

 

 

Thanks, Alice

3 replies

david_r
Celebrity
  • August 21, 2014
Hi,

 

 

you can use an AttributeCreator to get a reference to a preceeding feature's sample date:

 

 

 

 

Then format both the current and the preceeding sample date into the number of seconds since epoch:

 

 

 

 

Finally, calculate the difference between the two values and convert seconds to hours:

 

 

 

 

David

fmelizard
Safer
Forum|alt.badge.img+18
  • Safer
  • August 21, 2014
Or just download the DateDifferenceCalculator from the FME Store.

takashi
Influencer
  • August 21, 2014
Hi,

 

 

In addition to David's suggestion, you can use Conditional Value setting in the AttributeCreator to differentiate sequences of each Site. That is, only if the Site Name is equal to the previous feature's Site Name, assign feature[-1].SampleDateTime to PrevSampleDateTime.

 

 

 

And then, calculate the time difference if the PrevDateTime is not empty.

 

 

Takashi

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings