Question

Automatically generating time variables

  • 29 April 2022
  • 4 replies
  • 26 views

Hello.

 

I have a workspace that runs locally, which takes two user inputs (stored as user parameters) - a start date (the first date of the PREVIOUS month) and end date (last date of the previous month). When the workspace is run it asks for each date from the user, and they would provide them as '01/03/2022', for example. The dates are then fed into an SQLExecutor and used to help query our database. The workspace is run each month.

 

I would like to run this process automatically on FME server, but to do this obviously a user can't manually specify dates. I therefore need a way for the bench to generate the start and end dates of the previous calendar month. The bench would always be run on or after the first day of the CURRENT month, but not always on the same day (so I can't just use today's date minus a day, for example).

 

I'd prefer to do this in FME, but if it has to be done in the SQLExecutor query that would be fine as well.

 

Thanks in advance.

Liam Riddy


4 replies

Userlevel 3
Badge +26

I have attached a workbench that will do this in an AttributeCreator or AttributeManager.

 

image

Userlevel 3
Badge +26

I just realized the formatting of the date. You can add additional DateTimeFormatting to get you desired format.

image

Userlevel 6
Badge +31

If you want to have these as private parameters you can use python:

StartDate:

from datetime import date, timedelta
 
last_day_of_prev_month = date.today().replace(day=1) - timedelta(days=1)
start_day_of_prev_month = date.today().replace(day=1) - timedelta(days=last_day_of_prev_month.day)
 
return start_day_of_prev_month.strftime("%d/%m/%Y")

EndDate:

from datetime import date, timedelta
 
last_day_of_prev_month = date.today().replace(day=1) - timedelta(days=1)
 
return last_day_of_prev_month.strftime("%d/%m/%Y")

 

Thanks for responses. Both work nicely.

Reply