Current date format

Hi,

Any Idea how can get the current date of execution of a workflow as10-JAN-20 and so on for all months and days of the year?

Hi @Adiwakar

Did you check the Extract Contect Properties node, already,
gr. Hans

I’m not sure if the Extract Context Properties will give the current Data/Time. I think it gives the time of the last modification to the workflow.

You can use the Data&Time Configuration node and check the box to use execution time to generate the current Date/Time though.


2 Likes

So, the Date and Time Config node does not let me get the current date in the format I wanted in the original post. I know there are many ways in KNIME to get the current date but they are all in numeric format (as a date should be). But because of a weird requirement, I need to know if there a way to get the current date like 10-JAN-20. Even if it is given out as a string and not a date format that is ok.

Hi @Adiwakar,

Please check this workflow and let me know if this is what you are looking for:

legacy_time_manipulation.knwf (21.5 KB)

I created the time range using the Create Date&Time Range node, then used the Date&Time to legacy Date&Time node and Time to String (legacy) and finally the String Manipulation node with this expression:

upperCase(regexReplace($Date&Time$, "(\\d{2})\\.(.{3})\\.\\d{2}(\\d{2})", "$1-$2-$3"))

The output:

:blush:

4 Likes

Hi there @Adiwakar,

Date type can’t be in this format. But as @armingrudd showed you can do certain manipulation to get it into desired format but as String type. I would use Column Expression node for this with following syntax:

day = substr(column(“Date&Time”),8,2)
year = substr(column(“Date&Time”),2,2)

switch(substr(column(“Date&Time”),5,2)) {
case “01”:
month = “JAN”;
break;
case “02”:
month = “FEB”;
break;

}

join(day,“-”,month,“-”,year)

Br,
Ivan

3 Likes

I tried this

day = substr(column(“TCPS_RESPONSE_RECEIVED_DATE”),3,2)
year = substr(column(“TCPS_RESPONSE_RECEIVED_DATE”),8,2)

switch(substr(column(“TCPS_RESPONSE_RECEIVED_DATE”),0,2))
{
case 01:
month = “JAN”;
break;

}
join(day,"-",month,"-",year) // error at this line month not defined

gave me an error saying that the month was not defined. how am I supposed to define this and more importantly where?

Hi @Adiwakar,

this is a pretty simple workflow that does not use legacy nodes:
image

If you are fine with ‘23-Jan-20’ as output, you don’t need the String Manipulation node which converts ‘Jan’ to ‘JAN’. The last node simply gives you a flow variable if desired.

Here is the workflow to download: current_exec_date.knwf (10.8 KB)

Cheers,
Simon

3 Likes

Hi there @Adiwakar,

the reason for the error is missing quotes around 01. So it should be case “01” cause 01 is a string. Anyways I would go with @SimonS solution :slight_smile:

Br,
Ivan

1 Like

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