Skip to main content
Solved

Comparing dates in FME


Hi there,

 

I am trying to filter (using tester) the data on the basis of dates (i.e. month and Year). I have converted the dates into desired format using DateTimeFormat function. When I run the tester, it does not give the right result. In the passed data tab I could see the dates row that should have been in the failed data tab. I have attached the screen shot of my test parameter. Could anyone guide where am I making the mistake?

Best answer by takashi

Hi @muhammad_yasir, If you convert the datetime format into Standard FME Date/Time Format, you can compare the datetime values by setting the Comparison Mode parameter in the Tester to "Date/Time".

View original
Did this help you find an answer to your question?

11 replies

If you can't see the logic of the tester here is the value

@DateTimeFormat(@DateTimeParse(@Value(INCIDENT_TIME), %Y-%m-%d),%m %Y) >= @DateTimeFormat(@DateTimeAdd(@DateTimeNow(),-P8M),%m %Y)

AND @DateTimeFormat(@DateTimeParse(@Value(INCIDENT_TIME), %Y-%m-%d),%m %Y) <= @DateTimeFormat(@DateTimeAdd(@DateTimeNow(),P3M),%m %Y)

 


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • Best Answer
  • December 18, 2019

Hi @muhammad_yasir, If you convert the datetime format into Standard FME Date/Time Format, you can compare the datetime values by setting the Comparison Mode parameter in the Tester to "Date/Time".


takashi wrote:

Hi @muhammad_yasir, If you convert the datetime format into Standard FME Date/Time Format, you can compare the datetime values by setting the Comparison Mode parameter in the Tester to "Date/Time".

@takashi I just tried that. But ended with the same result.


takashi wrote:

Hi @muhammad_yasir, If you convert the datetime format into Standard FME Date/Time Format, you can compare the datetime values by setting the Comparison Mode parameter in the Tester to "Date/Time".

Hi @takashi, I just noticed that I am getting following warning message when I run the tester.

Tester (TestFactory): TestFactory: Unable to do a date/time comparison of 'yyyymm' and 'yyyymm'. Comparing as strings instead.


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • December 18, 2019
takashi wrote:

Hi @muhammad_yasir, If you convert the datetime format into Standard FME Date/Time Format, you can compare the datetime values by setting the Comparison Mode parameter in the Tester to "Date/Time".

My intention was to set these expressions. Both @DateTimeParse function and @DateTimeAdd function return a datetime value formatted in Standard FME Date/Time Format.

Doesn't this work for you?

@DateTimeParse(@Value(INCIDENT_TIME), %Y-%m-%d) >= @DateTimeAdd(@DateTimeNow(),-P8M)
AND
@DateTimeParse(@Value(INCIDENT_TIME), %Y-%m-%d) <= @DateTimeAdd(@DateTimeNow(),P3M) 

Comparison Mode: Date/Time


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • December 18, 2019
takashi wrote:

Hi @muhammad_yasir, If you convert the datetime format into Standard FME Date/Time Format, you can compare the datetime values by setting the Comparison Mode parameter in the Tester to "Date/Time".

If you need to compare only year and month part, this expression would be available.

@DateTimeFormat(@DateTimeParse(@Value(INCIDENT_TIME), %Y-%m-%d),%Y%m) >= @DateTimeFormat(@DateTimeAdd(@DateTimeNow(),-P8M),%Y%m)
AND
@DateTimeFormat(@DateTimeParse(@Value(INCIDENT_TIME), %Y-%m-%d),%Y%m) <= @DateTimeFormat(@DateTimeAdd(@DateTimeNow(),P3M),%Y%m)

takashi wrote:

Hi @muhammad_yasir, If you convert the datetime format into Standard FME Date/Time Format, you can compare the datetime values by setting the Comparison Mode parameter in the Tester to "Date/Time".

Awesome. It worked. Thanks for clarification. Last thing, Can I add multiple but different conditions in single tester? If yes, Can you explain how?


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • December 18, 2019
takashi wrote:

Hi @muhammad_yasir, If you convert the datetime format into Standard FME Date/Time Format, you can compare the datetime values by setting the Comparison Mode parameter in the Tester to "Date/Time".

Consider using TestFilter instead.


takashi wrote:

Consider using TestFilter instead.

Is it the same as Tester ?


takashi wrote:

If you need to compare only year and month part, this expression would be available.

@DateTimeFormat(@DateTimeParse(@Value(INCIDENT_TIME), %Y-%m-%d),%Y%m) >= @DateTimeFormat(@DateTimeAdd(@DateTimeNow(),-P8M),%Y%m)
AND
@DateTimeFormat(@DateTimeParse(@Value(INCIDENT_TIME), %Y-%m-%d),%Y%m) <= @DateTimeFormat(@DateTimeAdd(@DateTimeNow(),P3M),%Y%m)

This condition does not work. However, above mentioned condition does work


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • December 18, 2019
takashi wrote:

Consider using TestFilter instead.

Similar to the Tester, but you can add any number of output ports for the number of your desired conditions. See the help on the TestFilter transformer to learn more.


Reply


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