Question

How to create a private parameter so that when features are written they have the date and time along with the name of the file, also with some attribute value like STATE.

  • 17 September 2021
  • 2 replies
  • 3 views

Badge

Suppose there are some features in different state, I want those features to be written like that: ABC_STATENAME_DATETIME.xls.,, so that all the features for a particular state are written in a separate file with datetime and all features in other state are written in other file like that. I tried using attributevalue and datetimeformat in feature writer but it was taking too much time because datetime was being calculated for million for features that were coming in. I just want it to be a 1 file with a final timestamp, not multiple. Any easy/fast way?


2 replies

Userlevel 6
Badge +31

One way to do this is to create a (Python) scripted parameter, something like:

import datetime
datetime.datetime.now()

And use that in the fanout. All the data will get the datetime from the start of the run.

Userlevel 4

One way to do this is to create a (Python) scripted parameter, something like:

import datetime
datetime.datetime.now()

And use that in the fanout. All the data will get the datetime from the start of the run.

I agree about the solution (I use it myself quite often), but you'll have to format the output from now() to get a string that FME will accept as a return value. Example:

import datetime
n = datetime.datetime.now()
return n.strftime('%Y%m%d')  # Example: '20210921'

Incidentally, the formatting codes used by strftime() are identical to the DateTimeConverter, so it's easy to adapt to whatever you need.

Reply