Skip to main content
Hi,

 

 

I have 2 dates in the format 20130831000000 (DATE) and 20130905000000.000000 (TIMESTAMP).

 

How can i subtract them in FME in a way that the format of answer is in days (eg. 5) ?

 

 

I used dateformatter in FME to convert them to 2013/08/31 but the TIMESTAMP-DATE doesn't react properly.

 

 

Greetings, Pieter
Hi Pieter,

 

 

As far as I know, FME currently doesn't support simple calculating function for date / datetime values. You will have to append the functionality with creating a custom transformer or defining a python script. Or, you can also consider to use the DateDifferenceCalculator custom transformer from FME Store.

 

http://fmestore.safe.com/transformers/DateDifferenceCalculator.htm

 

 

Takashi
Currently the store transformer is the way to go to do calculations on dates.
Hi,

 

 

here is a solution pased on a PythonCaller:

 

 

-----

 

import fmeobjects from datetime import date from time import strptime   def FeatureProcessor(feature):     # Get attributes     my_date = feature.getAttribute("my_date")     my_timestamp = feature.getAttribute("my_timestamp")          # Parse string attributes to time objects     t1 = strptime(my_date, "%Y%m%d%H%M%S")     t2 = strptime(my_timestamp, "%Y%m%d%H%M%S.000000")       # Convert to date objects     d1 = date(t1.tm_year, t1.tm_mon, t1.tm_mday)     d2 = date(t2.tm_year, t2.tm_mon, t2.tm_mday)          # Number of days between the two dates     day_delta = abs((d1 - d2).days)          # Set result attribute "delta"     feature.setAttribute("delta", day_delta) -----

 

 

It requires two attributes "my_date" and "my_timestamp" and will return a new attribute "delta" which will correspond to the number of days between the two input dates.

 

 

David
Hi,

 

Thanks for your reply and support, it works now !

 

 

I first upgraded from FME2012 to FME2013

 

There i used de dateconverter to convert de date-field to timestamp-format %Y%m%d%H%M%S.000000'

 

With de DateDifferenceCalculator i managed to calculate the difference in days.

 

 

Pieter

 


Reply