Date and datetime conversions in workflows and components

  • 29 March 2024
  • 1 reply
  • 20 views
Date and datetime conversions in workflows and components
Userlevel 3
Badge +1

When you create a workflow that runs components you sometimes want to pass through dates or datetimes from the workflow to the component. As far as I know you can only pass parameters as strings. Because this is how you pass on the parameters in a Run DQC task:

 

So what if you still want to use that date or datetime info in your component?

 

Prepare the date time info in your workflow

So first of all we want to make sure that that load_datetime string contains all the date and time info we want. I've done this in a global variable in the workflow.

So this is my expression for load_datetime:

toString(now(), 'yyyyMMddHHmmss')

(in case you didn't know: you can get to the Global Properties of your workflow by double clicking on the canvas of your workflow outside the tasks)

And it looks like this:

 

My workflow only consists of a Run DCQ Task:

The configuration of it you can already see in the first screenshot in this post.

 

The component

I've created a component with the sole task of demonstrating date conversions.

 

The Random Record Generator is only there because the component has to start somewhere.

The first Alter format step (Get load vars from workflow) gets the parameters from the workflow (load_id and load_datetime). But I don't do any conversions yet.

We need to do an extra step to actually get the parameters from the workflow. Go to each parameter specifically. Right click on “Expression” and Map as Parameter:

Put in the name of the workflow parameter:

This all still has nothing to do with date/datetime conversions. For that we go to the next Alter Format step.

 

Here I add two columns.

The load_datetime_date column will get the date format. To present the expression here in copy-pastable and searchable fashion, it is:

toDate(load_datetime, 'yyyyMMddHHmmss')

And the datetime conversion is this:

toDatetime(load_datetime, 'yyyyMMddHHmmss')

 

The last step is a Text Writer where we can check our work. We run the workflow, it runs the component and here is the result:

 

The randomdate is from the Random Record Generator, but I didn't use it further.

You can see the original load_datetime parameter, which is a string. And load_datetime_date and load_datetime_datetime have their converted results.

Hope that helps anyone who looks for examples of these.


1 reply

Userlevel 6
Badge +7

Thank you for taking the time to share your best practices @Marcel-Jan 🙌

Reply