Question

passing a date from python as a published parameter

  • 3 November 2016
  • 2 replies
  • 42 views

I am trying to create a workspace that when run will pull the current date into python (either as start up script or python caller) and then pass that date out as a published parameter in FME. I have the following in python:

import datetime

 

today = datetime.datetime.now()

 

#print str(today)

 

print today.strftime("%Y%m%d")

This gives me the date (for today) as 20161103

I want to pass that out as a Published or Private Parameter [Start_Date] to be read in a transformer later in the process.

I will also need to be able to calculate a date two weeks away and pass that as [End_Date].


2 replies

Badge +3

Hi jimq66, 

You don't need to use a startup script, neither a Python caller. You can initiate a Published/Private parameter with type "Scripted (Python)".

0684Q00000ArLuhQAF.jpg

The code I use in my example is:

from time import strftime
return strftime("%Y%m%d-%H%M%S")

Python documentation can be found here.

Badge

Hi @jimq66

you can't set parameter value once translation has started. However, rather than a published parameter value you can use an attribute value in your transformer.

 

 

If every feature in your workflow goes through TimeStamper, every feature will have e.g. _startdate attribute with the current datetime added to it by the time it reaches the transformer that needs to use the current date.

 

 

To calculate 'two weeks from now' you currently have two options:
  • you can use DateTimeCalculator custom transformer to add 14 days to the current date or
  • you can construct a value that consists of current YYYYMMDD followed by '14 days' and let DateFormatter format the value into e.g. FME Date (%Y%m%d).

Please take a look at the screenshot. I will also attach the sample workspace.

twoweeks.fmw

Reply