Node String to Date (Legacy) has error !!?

Hi Team,

I have some question about string to Date/Time(Legacy) Node.

Ref. figure1

my data has date format {“dd/mm/yyyy”} but this node execute to {“dd/Jan/yyyy HH:ss”} that mm (month) is goto Hour and mm has replaced on 01 auto.

image

On my objective, I will need to change date format (cleansing) in columns because my data is mix format

image

If someone have any solution,Please help to suggest me. Many Thanks

my data has date format {“dd/mm/yyyy”} but this node execute to {“dd/Jan/yyyy HH:ss”} that mm (month) is goto Hour and mm has replaced on 01 auto.

The node is working correctly. and it did exactly what you told it to. You told it that the RequestDate column contains date/time values that consist of a day, minutes, and a year, and so that’s what it returned.

From the RequestDate column, it grabbed the day, filled in January for the month since you didn’t specify a month, grabbed the year, assumed 00 hours since you didn’t specify hours, grabbed 11 minutes like you instructed, and then 00 seconds.

The syntax you should be using is dd/MM/yyyy.

The default entry in the String to Date/Time (legacy) node shows you what should be capitalized and what shouldn’t
image

OK, I used “dd/MM/yyyy” it is show correctly but if I need to show month on numeric format, can’t it ?

at the first, I might be confused on Node function to using it. By Default, My data on date is string so I use String to Date before change format date. On another way, you suggest to use “dd/MM/yyyy” exactly. It is OK data of date change to Column Type Date.

Pls see other picture, I used compare format “dd/MM/yyyy” vs “dd/mm/yyyy”
image
image
image

the result is correctly? MM is meaning show short name of month right but MM vs. mm result is difference Why?

and Question for this function user define date format no time why result show time ? I did not understand.

I don’t really understand your most your last post.

If you want to keep everything numeric, then use the updated String to Date&Time node:

image

1 Like

Hello @kritsapatw,

I would suggest to use standard String to Date&Time node and then if something is not working properly or you are wishing something else feel free to explain it and we’ll do our best to assist you :wink:

Br,
Ivan

Hi @kritsapatw

From your question, I think you should probably take a look at the help documentation for the String to Date&Time and Date&Time to String nodes, and specifically at the section titled “Supported placeholders in the pattern”.

But with regard to a couple of the specific questions you have raised, the difference between MM and mm is that MM represents “Months”, while mm represents “minutes”. These “placeholders” come from Java Simple Date Format, so if you search for that on the web you should find plenty of resources on it, if you require more information than you can find in the KNIME documentation.

When it comes to formatting of dates, the specific output that you get is dependant on your chosen system locale/language. However, these are the patterns it uses for Months (which unfortunately are not described in the documentation for the nodes, which is why I recommend research Java Simple Date Format):

M = either a single or two digit month number (i.e. 1-12) with number of digits according to the value (e.g. <10 → 1 digit, or >=10 → 2 digits)
MM = always a two digit month number so 01-12
MMM = Abbreviated month name, so in UK Jan, Feb, Mar and so on
MMMM = Full month name, so in UK January, February, March

mm on the other hand means minutes, so as @elsamuel pointed out, if you choose dd/mm/yyyy, then you are going to get day/minute/year, which is unlikely to be what you want! :wink:

When it comes to output format of a date or datetime, you need to understand that the output that KNIME produces is according to the java renderer which produces the output in a human-readable form. A date or datetime has no inherent “format”, it is just held internally as a number representing the elapsed period relative to the “epoch” (1 January 1970). If you want to output a date or datetime in a specific format other than the default representation used by the KNIME/Java renderer you need to convert it to a String, and tell the converting node the format that you require.

So if you already have your date in a String in one format, and you wish to output it in a different format, then you need to do the following:

Steps

  1. Convert String to Date&Time telling it the current input format of the String so it knows how to interpret it, and store it correctly in a Date/Time object
  2. Convert Date&Time to String telling it the required output format so that it can render it back into a String of the desired format.

The conversion back to String is best done at the point where you want to output it in a specific format. I would suggest leaving it as a Date/Time object during all other processing where the specific output format is not required, as you can then act on it correctly as a date/time (e.g. sort on it, add days, find difference between dates and so on) which you cannot necessarily do once it has become a String.

In summary, for outputting date and datetime values to a report or anything else where a specific format is required, you should always be outputting a String representation of your value, and not the actual datetime object itself.

I hope that helps clear up some of your questions.

Many thanks, Ipazin for your supporing. In some case, I try a lot of change and using String to Date&Time (standard). I didn’t understand about recognize engine of it. Some data can read but another cannot. so I used Legacy is feel free to easy of usage. OK I will study to use it more.

1 Like

Very thankful takbb. your answer is more clearly.

1 Like

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