Skip to main content
How do I convert an FME date field (%Y%j) to a number so that I can complete arithmetic comparisons?
Hi,

 

 

The DateFormatter can be used to change date format. But I think %Y%j format is available to perform comparisons {<, <=, >, >=, ==, !=}. What kind of comparison do you need?

 

 

Takashi
Thanks for responding Takashi.  I was having trouble comparing two dates because I wanted to add 5 days to one of the values before comparison.  I managed to do it myself last night by using the Tester transformer (after formatting both dates as %Y%j) and adding 5 days to one of the dates in the comparison rather than before the comparison:

 

Date1 > @evaluate(@Value(Date2)+5)
You can compare 2 date strings in %Y%j format with the Tester, but as far as I know, existing FME transformers cannot do date calculation. e.g. a date + 5 days.

 

If you need to perform date calculation in a workspace, consider using script.

 

-----

 

# Python Script Example (for PythonCaller)

 

# Assume input feature has attributes called

 

# '_year', '_month', '_day', '_diffDays'.

 

import fmeobjects, datetime

 

def addDays(feature):

 

    year = int(feature.getAttribute('_year'))

 

    month = int(feature.getAttribute('_month'))

 

    day = int(feature.getAttribute('_day'))

 

    diff = int(feature.getAttribute('_diffDays'))

 

    newDate = datetime.date(year, month, day) + datetime.timedelta(days=diff)

 

    feature.setAttribute('_newDate', newDate.strftime('%Y-%m-%d'))

 

-----
ah, I found a custom transformer called DateCalculator in the FME Store. It can be used to add days to a date.

Reply