Skip to main content
Solved

Date Range Query


Forum|alt.badge.img

Hello. I realize there are several different date range topics, and I can't seem to find one that applies to my needs.

My goal is to query or tag records within 90-, 270-, 365-day date ranges based on CurrentDate. I have not been able to get anything to work with FME tools, but normally the SQL query would be:

Select * from [layer] where "expiration_date" >= CurrentDate+90

Any ideas?

Thanks.

Best answer by hollyatsafe

Hi @ronaldmcoker

In order to perform date calculations in FME I believe your date attribute will need to be in FME format - you can use the DateTimeConverter to do this. 

You can then use the DateTimeStamper to get todays date and then use the DateTimeCalculator as mentioned already. 

Alternatively you can perform date calculations in any text editor using the datetime functions. E.g in a tester set the left value to your expirydate the operator to <= and right value to:

@DateTimeAdd(@Value(_timestamp),P90D)

And the mode to Date/time. The data will then come out of the passed or failed ports accordingly. 

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

7 replies

danilo_fme
Evangelist
Forum|alt.badge.img+41
  • Evangelist
  • July 10, 2018

Hi @ronaldmcoker

There is a transformer DateTimeCalculator.

It could be interesting for you.

Thanks,

Danilo


Forum|alt.badge.img+2
  • Best Answer
  • July 10, 2018

Hi @ronaldmcoker

In order to perform date calculations in FME I believe your date attribute will need to be in FME format - you can use the DateTimeConverter to do this. 

You can then use the DateTimeStamper to get todays date and then use the DateTimeCalculator as mentioned already. 

Alternatively you can perform date calculations in any text editor using the datetime functions. E.g in a tester set the left value to your expirydate the operator to <= and right value to:

@DateTimeAdd(@Value(_timestamp),P90D)

And the mode to Date/time. The data will then come out of the passed or failed ports accordingly. 


Forum|alt.badge.img+2
hollyatsafe wrote:

Hi @ronaldmcoker

In order to perform date calculations in FME I believe your date attribute will need to be in FME format - you can use the DateTimeConverter to do this. 

You can then use the DateTimeStamper to get todays date and then use the DateTimeCalculator as mentioned already. 

Alternatively you can perform date calculations in any text editor using the datetime functions. E.g in a tester set the left value to your expirydate the operator to <= and right value to:

@DateTimeAdd(@Value(_timestamp),P90D)

And the mode to Date/time. The data will then come out of the passed or failed ports accordingly. 

In a text editor select Help>Date/Time Functions for more information on how to use these

 

 


Forum|alt.badge.img
hollyatsafe wrote:

Hi @ronaldmcoker

In order to perform date calculations in FME I believe your date attribute will need to be in FME format - you can use the DateTimeConverter to do this. 

You can then use the DateTimeStamper to get todays date and then use the DateTimeCalculator as mentioned already. 

Alternatively you can perform date calculations in any text editor using the datetime functions. E.g in a tester set the left value to your expirydate the operator to <= and right value to:

@DateTimeAdd(@Value(_timestamp),P90D)

And the mode to Date/time. The data will then come out of the passed or failed ports accordingly. 

Thanks so much. I've been messing around with this combination of transformers. I'll try this out!

 

 


Forum|alt.badge.img
hollyatsafe wrote:

Hi @ronaldmcoker

In order to perform date calculations in FME I believe your date attribute will need to be in FME format - you can use the DateTimeConverter to do this. 

You can then use the DateTimeStamper to get todays date and then use the DateTimeCalculator as mentioned already. 

Alternatively you can perform date calculations in any text editor using the datetime functions. E.g in a tester set the left value to your expirydate the operator to <= and right value to:

@DateTimeAdd(@Value(_timestamp),P90D)

And the mode to Date/time. The data will then come out of the passed or failed ports accordingly. 

I'm not having any luck with the DateTimeStamper/DateTimeConverter/Tester combination. All outputs from DateTimeConverter are failing in the Tester, and the Failed products contain features with all dates (unfiltered).

 

 

I've attached my translation if you'd like to review (20180710-datequeries-testing.fmw).

 

 

*****

 

 

Made some changes to Date only (instead of Datetime conversions) and changed the Tester mode to Date/Time.

 

 

"Tester(TestFactory): TestFactory: Unable to do a date/time comparison of '20120527' and 'DateTimeAdd(20180711, P90D)'.  Comparing as strings instead"

 

 

 

 


Forum|alt.badge.img+2
hollyatsafe wrote:

Hi @ronaldmcoker

In order to perform date calculations in FME I believe your date attribute will need to be in FME format - you can use the DateTimeConverter to do this. 

You can then use the DateTimeStamper to get todays date and then use the DateTimeCalculator as mentioned already. 

Alternatively you can perform date calculations in any text editor using the datetime functions. E.g in a tester set the left value to your expirydate the operator to <= and right value to:

@DateTimeAdd(@Value(_timestamp),P90D)

And the mode to Date/time. The data will then come out of the passed or failed ports accordingly. 

Hi @ronaldmcoker

 

For the date/time functions to work they need to be preceded by @ . Instead of typing this in by hand in the text editor you can add these functions from the menu on the left hand side - please see picture attached. 0684Q00000ArMGMQA3.png

 


Forum|alt.badge.img
hollyatsafe wrote:
Hi @ronaldmcoker

 

For the date/time functions to work they need to be preceded by @ . Instead of typing this in by hand in the text editor you can add these functions from the menu on the left hand side - please see picture attached.

 

@hollyatsafe I think that did it! Thank you!

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