Date type Workflow Variable

Hi,
I need a DateTime variable to be reachable from any node.

However, KNIME allows me only to create String, Double or Integer workflow variables. Since I think these are the only variables with the feature I need, I don´t know exactly what to do.

Is there any way to make it?

Cheers

Say, String to Date&Time node will do it.

Hey izaychik, thanks for your reply.

I understand that the String to Date&Time node does only take columns as input. Even if it did take variables, I think the output would be lost in the flow unless I make sure it is connected to every single node (which is not an option).

Do you see a way for it to be useful anyway?

Nodes may keep you variable. At least in my case, I assigned path variable in Excel reader and it was transferred along the whole WF.

Hi @francisco_munoz_m,

i hope this short example helps you.
I have defined a workflow variable as String containing a Value in date format and set filters with and without manipulation of the variable.

BR
Hermann
Example.knwf (15.3 KB)

Thank you @morpheus

I find interesting how you compare a Date with a “date format” String. However, I don’t think I can use that trick every time.
In my specific case, what I need is to replace this:

LocalDate NOW = java.time.LocalDate.now();

with something like this

LocalDate NOW = date_Workflowvariable

Let me know if I didn’t get your point, cheers

Was that node connected to entire wf though?
Also, I just noticed that KNIME apparently does not allow to create date type variables at all.
Am I wrong?

You can do it directly using Date&Time Widget. The format is 2020-04-29.

Hi @francisco_munoz_m,
i am not sure if i understand your question correct.
You have the option to define variables. First as workflow variable (right click on the opened workflow in the explorer or second you can define new one in the Java Edit Variable node.
The First one are available without variable port connection, the second one you have to connect to your nodes.

BR
Hermann

Thanks @morpheus

What I need is a Date type variable, available without port connection. Unfortunately, it seems that KNIME only allows me to create String, Integer or Double type variables, not Dates. Therefore my issue.

Problem solved.

I just created a String workflow variable with the format “yyyy-mm-dd”. Since I only require it while using a Java Snippet node, I just use a method to turn it into a Date variable (which serves only the node’s code) each time.

For example:

workflow_var = “2020-12-15”

Then, inside the node’s code:

LocalDate code_var = LocalDate.parse(workflow_var)

or (in case you haven’t explicitly imported the java.time.LocalDate library)

java.time.LocalDate code_var = LocalDate.parse(workflow_var)

In case I need the time, I just take it as 12 PM and replace LocalDate with LocalDateTime:

LocalDateTime code_var = LocalDateTime.parse(workflow_var + “T12:00”)

java.time.LocalDateTime code_var = java.time.LocalDateTime.parse(workflow_var + “T12:00”)

Cheers

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.