Excel data, date column in excel when read in knime was reading in 2 different formats

Input file used : Test_Data.xlsx (377.8 KB)

Used Excel reader to read this file and the output isas below
image

what could eb causing this issue and how can i fix it

There’s something wrong with the data formatting in your Excel file. I’m not sure what’s causing the problem, but you should investigate what’s going on back at Excel. Here’s what the data looks like when converted to text.

1 Like

@chaithuj you could try something like this

1 Like

Another approach is just to chain String to Date&Time nodes, making sure you have unticked “Fail on error” and then use Column Merger to merge the results:

image

image

2 Likes

But the “simplest” solution is to do it all in a single String to Date&Time using “optional” date masks:

[yyyy-MM-dd][dd/MM/yyyy]

This will convert both dates within the same column

7 Likes

@takbb I clicked “Like” for your last solution, but I’ve got to comment. That’s a stroke of genius. I would have never figured that out. Kudos to you.

3 Likes

Thanks @rfeigel ! Too kind :slight_smile:

I should add a cautionary note. It is possible to get “carried away” with the date/time masks though, as I once did, as it can be tempting to see what is possible with lots of optional values to create some kind of “universal data mask”!. This would make the mask very long, and if you do that, you may find that you inadvertently make the node difficult to configure, in future as it becomes over-wide… as described in this post (along with the fix should you ever find yourself in that situation)

Thanks for the heads up. There’s never a free lunch.

1 Like

@takbb, Thanks a lot for your time helping me
Perfect, it was able to handle both date formats and convert to yyyy-mm-dd
Is there a way we can get the output as MM/dd/yyyy

image

Thank you @mlauber71

@takbb, I was able to add one more Date&Time to String to get the format, i wanted
image
image

1 Like

Hi @chaithuj , once you have the date being held as an actual Date datatype, technically it has no format. A date only has a format when it is rendered but unfortunately I don’t think there is an option in KNIME to change the format in which Date datatypes are rendered.

To display in a different format, you need to convert it back to a String and describe the format that you want:

e.g. using the Date&Time to String node, and specifying a format of MM/dd/yyyy

EDIT: I see you found the same answer while I was writing this! :wink:

Thanks @takbb
Your solution is brilliant and simplest.
Thanks a lot for all the help

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