Beginner String to Date Question

Coming from only using formulas in Excel, I know I have a long way to go to really learn and harness the power of KNIME. I have gone through most of the modules here and haven’t been able to track down or figure out on my own a problem I’ve been having with a csv I’m working with.

I am pulling in data from a csv where the dates are formatted as mm/dd/yyyy and are being read as strings. In cases where the month or day is a single digit, it is read as 1/1/2018 not 01/01/2018. This has made converting from a string to date difficult. Is there a way to facilitate this through nodes? I’m sure there’s a Java snippet way of doing it, but at my level, that’s beyond me at this point. Thanks in advance!

Hi @Blas

if you have two digits in the code (like mm) the format expects that the string is also two digits. So you need to remove one to match single signs as well.

In you case it is m/d/yyyy and this will macht the 1/1/1999 as well as the 10/1/2099

Cheers, Iris

I thought about trying to split based on length, then join back together to deal with m/d/yyyy, mm/d/yyy, and m/dd/yyyy issues, however the only way I could think to do so was by length. Then the issue would be with differentiating between a one digit month or one digit day.

Hi @Blas,

You can use the String To Date&Time node and set the date format to M/d/yyyy. This will automatically detect if there are single or two digits in the String.


1 Like