Skip to main content

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

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


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


Hi @gisballarat

you might also want to try DateCalculator custom transformer.


Hi @gisballarat ,

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


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


Reply