Error in Conversion of String format to Date format

Hi,

When I use the node String to Date&Time format, in ver 5.2, I am getting the following error message.

java.lang.reflect.invocationTargetException.
image

Pls advise

Thanks
KRISH

Hi @PKRISH , what format mask are you using for the conversion?

1 Like

Hi @PKRISH,

Apparently, there is a leading space character which causes the issue.
You can use the strip() function in the String Manipultion node to remove leading/trailing whitespaces:
strip($date$)

Update: It seems that there is a minor issue in the error message and the underline starts one char early (AP-21720). So, the issue here is not a leading space character in the string value.

Would you check your pattern in the String to Date&Time node and make sure there is no leading space in your pattern?
dd-MM-yyyy

2 Likes



Hi,
Thanks for your response. As suggested, I removed the leading and trailing blanks and then used the node " string to datetime". No effect. I still get the same error message. I am attaching herewith the screen shots

Thank you @PKRISH,

I have updated my first reply.
So, by looking at your configuration and the pattern used in the String to Date&Time node (and thanks to @takbb who first asked for it), it appears that your pattern doesn’t match the date format in your data table. You have used yyyy-MM-dd in the node’s configuration but regarding the error message, the date format is dd-MM-yyyy (18-04-2008).

2 Likes

Hi Armin.
I was trying various combination of date format and inadvertently pasted a wrong screen shot. I am attaching the correct screen shot with the correct settings. Despite this, I am getting the same error message.


image

Could you throw light on what could be creating the problem

You are trying to convert dd-MM-yyyy to dd.MM.yyyy which is why the node is complaining :wink: If you change the Date format in the node to dd-MM-yyyy it will start working.

1 Like

I do not see a format as dd-MM-yyyy in the drop down. Could you advise. Thanks

You can just type it in, you’re not restricted to the examples in the dropdown menu. :slight_smile:

2 Likes

Hi Scott.
As suggested , i typed the date format as dd-mm-yyyy.



image
Different error message follows.
Thanks

Hi @PKRISH “mm” means “minutes”. You need to use “MM” (or just “M”) for month

2 Likes


Any idea of what the solution could be!

Hi @PKRISH , please note that the case is important. You need to be careful to use the examples as they were given. So the year yyyy remains lower case.

i.e. the format is:

dd-MM-yyyy
or
d-M-yyyy
(or variations of those)

The single d and single M allow for day and month both as single digit, or double digit or with leading zero. If you specify dd or MM it only matches where the day / month is represented as 2 digits. i.e. d and M are less restrictive than dd and MM

It’s not entirely obvious at first glance, but you get used to it.

The list of formats are those defined for java, and can be viewed here
DateTimeFormatter (Java Platform SE 8 ) (oracle.com)

2 Likes

Hi takbb.

Thanks for the solution. It worked. I was able to execute this node without error message. But the result was in the format of yyyy-MM-dd , though the setting was for dd-MM-yyyy. Any probable reason.
Regards

1 Like

Hi @PKRISH ,
The format mask you gave tells KNIME how to interpret the String, not how to represent a date once it is an actual date data type.

In common with databases and programming languages, once something is a date in KNIME it has no inherent format.

KNIME will always display dates in yyyy-MM-dd (sortable) format. If at some future point you need a date to be output in a specific format, you always have to convert it back to a String again, eg by using the Date&Time to String.

2 Likes

Thanks. I understand what you have to say reg the date format.

To resolve this, try using the date format ‘yyyy-MM-dd’. I’ve attached an image for your reference.

1 Like

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