How to convert string 2014-09 to YYYY-MM (Date format)

Dear Sir,

How to convert string 2014-09 to YYYY-MM (Date format) . I used string to Date& Time note but there is not such format for me to convert the string eg. 2014 -09 to YYYY-MM . I would like to ask any node or methods can use, thank you very much.

Hi @SIngpaore_knime,

Date format have 3 parts (year, month, date). Your kind of information is part of it. If you need to create a date type, you can use this node and set the first date to create a valid date.

Other tip is the kind of date&time type. If you set Date&Time, you need to set a full string. If you change it just for date, you can set YYYY-MM-01 and it be ok for knime, the resulto will be some dates with the start day.

If you need to extract information from an exists data column, you can extract it using Date&time extract node, but will still a string column, not a date format one.

I hope that it can help you.

BR, Denis

5 Likes

@SIngpaore_knime , as @denisfi says, a “date” does actually have to be a physical date, and a year and a month by itself does not identify an actual date. You will therefore have to arbitrarily choose the day of the month to represent the year-month. This would normally be the first of the month, and you could append the -01 using a String Manipulation node:
e.g.
join($MyColumnName$,"-01")

and then pass the result to the String to Date&Time node.

You can alternatively use the Palladian “Date Extractor” node with your sample data and it will automatically assign the date 01 to each month and year, and return a datetime for midnight on 1st of the month

image

4 Likes

Thank you both for your advice .

1 Like

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