Intermittent error from date/time input due to varying time granularity

HI everyone,

I’ve spotted what I believe is a bug - but maybe I’m doing something wrong? - when trying to use the Execution time from a Date&Time input node.

My use case is that I want to add a column that shows the current date/time. To do this I:

  • Get the current time from a Date&Time input node.
  • Connect the flow variable output to a Constant Value Column and append a new column taking value from the flow variable.
  • I then use the String to Date&Time node to convert the value to a local date time. [NOTE: Because the flow variable output is a string it seems that I’m forced to use the ‘String’ value setting in the Constant Value Column, which then forces me to do this step]

9 times out of 10 this works, but when the milliseconds of the current time end in a zero the flow variable only outputs 2 digits for the milliseconds (ie. 0.650 seconds is outputted as 0.65), which then causes the String to Date&Time node to fail with the following error:

ERROR String to Date&Time  0:2140     Execute failed: Failed to parse date in row 'Row0: Text '2022-03-10T09:09:33.65' could not be parsed, unparsed text found at index 19

I’ve managed to do a workaround to reduce the granularity to seconds (which in my case doesn’t matter) but it’s clunky - see below screenshot that shows at the top what I tried first (but fails 1 in every 10 attempts), and then at the bottom my workaround.

And the workflow is as follows:
DateTime_Intermittent_Error.knwf (31.9 KB)

Am I doing something wrong or is this a bug?

Many thanks,

Dom

hi @dpowyslybbe,

the problem is the date-time-format in your string to date&time node is not suitable.

I create timestamps like this:

br,
sven

3 Likes

That’s a very neat solution Sven and it meets my use case very nicely - thank you.

I’d not considered using the ‘Create Date&Time Range’ node in that way but I like it.

Thanks,

Dom

Hi @dpowyslybbe , the proper way to get the current time is definitely what @sven-abx has suggested, that’s how we usually do it.

Going back to what you were doing, and this is just for your own knowledge, and also if you decide to get the date/time as input interactively, instead of the workaround, you can use this fix by padding 0 on the right with padRight() with a length of 23 (“2022-03-10T09:09:33.650” has length 23).

Let’s say I have these values:
image

You can use this expression in a String Manipulation to pad 0 on the right to make up the length of 23:


padRight($column1$, 23, "0")

Results:
image

As you can see, those that have less than 23 characters will have 0 added to the right to make up 23 characters. Those that have 23 characters (or more) remain unchanged.

1 Like

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