Doing math with the actual date

Hi everyone!

Does anyone know IBM Modeler? I got this expresion in IBM Modeler:

datetime_date((date_in_days(@TODAY)-62) * 60 * 60 * 24)

So in brief, datetime_date() returns the date value for a number or string. date_in_days() the total of days, for example, from 20/04/2018 to 23/04/2018 we have 3 days. @TODAY is the value of the current date.

So, I know that I may have the exact result with Date Nodes, but I would prefer to do this more directly with maybe a JavaSnipet, I do not have much idea with JavaSnipets. I would be eternally glad if you can help me obtaining the actual date with JavaSnipet or the most closet equivalent in JavaCode.

Thanks!

Hi,

Insert this Java code into the “Java Snippet (simple)” node:

DateFormat dateFormat = new SimpleDateFormat(“yyyy/MM/dd”);
Date date = new Date();
return dateFormat.format(date);

Check Return type to “String”. Then use “String to Date/Time node” to convert String value to Date/Time
with the same format (yyyy/MM/dd).

Martin K.

1 Like

Hi dirojas,

To generate a current timestamp (KNIME LocalDateTime) using the Java Snippet node you can as follows:

out_timestamp = LocalDateTime.now();

You can also use a list of available function for manipulating with the generated timestamp:

Please find attached a sample workflow.

Best,
Anna

JavaSnippetDateTime.knar.knwf (3.2 KB)

4 Likes

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