Skip to main content
Solved

FME date field (%Y%j) to a number


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

Best answer by takashi

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
View original
Did this help you find an answer to your question?
This post is closed to further activity.
It may be a question with a best answer, an implemented idea, or just a post needing no comment.
If you have a follow-up or related question, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

4 replies

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • Best Answer
  • June 5, 2014
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

  • Author
  • June 6, 2014
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)

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • June 7, 2014
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'))

 

-----

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • June 7, 2014
ah, I found a custom transformer called DateCalculator in the FME Store. It can be used to add days to a date.

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