Skip to main content
Solved

Next Date Calculation


Hi All,

I am trying to calculate the next date from a starting date - for example Waste collection. I have a starting date in 2015 and would like to calculate the next pick up.

Pickup is every 7 days. In Excel you can using the CEILING function to round up to the next multiple of 7.

Is there any way that this function could be implemented in FME?

Thanks, Matt

Best answer by lenaatsafe

Hi @gisballarat

you might also want to try DateCalculator custom transformer.

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

5 replies

fmelizard
Safer
Forum|alt.badge.img+18
  • Safer
  • April 17, 2016

We're going to be attacking Dates and providing date arithmetic in FME 2017, but until then, I suspect Python is the way to go.

I managed to get this code to work in the PythonCaller (workspace attached). Ahead of time you'd need to get the attributes you want to work on set up -- I've hard coded the sample.

 

def input(self,feature):

yyyymmddStringFromFME = str(feature.getAttribute('date1'))

pythonDateTime = datetime.strptime(yyyymmddStringFromFME, "%Y%m%d%H%M%S")

oneWeek = timedelta(7)

oneWeekLater = pythonDateTime + oneWeek

yyyymmddStringForFME = oneWeekLater.strftime("%Y%m%d%H%M%S")

feature.setAttribute('date2',yyyymmddStringForFME)

self.pyoutput(feature)

Sample workspace attached. addoneweek.fmw


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • April 18, 2016

I usually use tcl "clock scan", "clock format" and "expr" to do such calculations mostly in transformers with a expressionevaluation capability. (attributecreator, testers etc.).


Forum|alt.badge.img
  • Best Answer
  • April 18, 2016

Hi @gisballarat

you might also want to try DateCalculator custom transformer.


  • April 19, 2016

Hi @gisballarat ,

You can use DateCalculator custom transformer. You need to provide the MM/DD/YYYY format as input.


Forum|alt.badge.img+5

@gisballarat, it was nice to know about this transformer and I like its UI however I tried but for some reason my translation comes out DC_Fail = N. So I just skipped it. I used @daleatsafe instead and it worked for me. I needed to subtract one week so I just changed the + symbol to a minus sign in his code. I'll be looking forward to the DateCalculator in 2017.


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