Skip to main content
Solved

Comparing dates in FME

  • December 18, 2019
  • 11 replies
  • 1013 views

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".

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, 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.

11 replies

  • Author
  • 30 replies
  • December 18, 2019

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
Celebrity
  • 7843 replies
  • 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".


  • Author
  • 30 replies
  • 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 I just tried that. But ended with the same result.


  • Author
  • 30 replies
  • 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".

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
Celebrity
  • 7843 replies
  • 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".

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
Celebrity
  • 7843 replies
  • 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".

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)

  • Author
  • 30 replies
  • 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".

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
Celebrity
  • 7843 replies
  • 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".

Consider using TestFilter instead.


  • Author
  • 30 replies
  • December 18, 2019

Consider using TestFilter instead.

Is it the same as Tester ?


  • Author
  • 30 replies
  • December 18, 2019

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
Celebrity
  • 7843 replies
  • December 18, 2019

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.