Nominal to Date

felix_w
felix_w New Altair Community Member
edited November 5 in Community Q&A

Dear Rapidminer Community

 

I am struggling again with some Nominal to Date conversions and I hope you can help me. I am extracting with an "extract macro" a date value and I am getting a nominal value. Now I want to convert this nominal value from the macro again back to a date value.

 

The nominal format is:

May 22, 2016

 

How can I convert this into date format? All I get is: "Cannot parse date" and I have tried already plenty of options.

 

Any help would be greatly appreciated!

 

Best regards

Felix

Answers

  • YYH
    YYH
    Altair Employee
    Answer ✓

    Hi @felix_w,

     

    You may have at least 2 ways to convert nominal string to a date by a customized date format.

     

    My example process attached here. Be careful that no quotes on the date string of the macro variable.

     

    date.PNG

    <?xml version="1.0" encoding="UTF-8"?><process version="8.1.001">
    <context>
    <input/>
    <output/>
    <macros/>
    </context>
    <operator activated="true" class="process" compatibility="8.1.001" expanded="true" name="Process">
    <process expanded="true">
    <operator activated="true" class="set_macro" compatibility="8.1.001" expanded="true" height="68" name="Set Macro" width="90" x="380" y="34">
    <parameter key="macro" value="someDate"/>
    <parameter key="value" value="May 22, 2016"/>
    </operator>
    <operator activated="true" class="generate_macro" compatibility="8.1.001" expanded="true" height="68" name="Generate Macro, method2" width="90" x="514" y="136">
    <list key="function_descriptions">
    <parameter key="nominalDate" value="date_parse_custom(%{someDate},&quot;MMM dd, yyyy&quot;,&quot;en&quot;)"/>
    </list>
    </operator>
    <operator activated="true" breakpoints="after" class="generate_data_user_specification" compatibility="8.1.001" expanded="true" height="68" name="Generate Data by User Specification" width="90" x="514" y="34">
    <list key="attribute_values">
    <parameter key="someDate" value="%{someDate}"/>
    </list>
    <list key="set_additional_roles"/>
    </operator>
    <operator activated="true" class="nominal_to_date" compatibility="8.1.001" expanded="true" height="82" name="Nominal2Date, method1" width="90" x="648" y="34">
    <parameter key="attribute_name" value="someDate"/>
    <parameter key="date_format" value="MMM dd, yyyy"/>
    <parameter key="keep_old_attribute" value="true"/>
    </operator>
    <connect from_op="Generate Data by User Specification" from_port="output" to_op="Nominal2Date, method1" to_port="example set input"/>
    <connect from_op="Nominal2Date, method1" from_port="example set output" to_port="result 1"/>
    <portSpacing port="source_input 1" spacing="0"/>
    <portSpacing port="sink_result 1" spacing="0"/>
    <portSpacing port="sink_result 2" spacing="0"/>
    </process>
    </operator>
    </process>

    YY

  • felix_w
    felix_w New Altair Community Member

    @: yyhuang thank you so much!! Now it finally works! :D 

     

    I still have one question though: Why does "MMM dd, yyyy" work for a date like this: "May 22, 2016"? I don't understand why those 3 "MMM" work, I thought for a month I would always write a double M ("MM").. which was also my mistake because I tried many variances of "MM dd,yyyy and nothing worked. 

     

    Felix

  • YYH
    YYH
    Altair Employee

    Hi @felix_w,

     

    Hope these links could help you understand better about the date formats.

     

    https://help.gooddata.com/cloudconnect/manual/date-and-time-format.html

    https://www.vsni.co.uk/software/genstat/htmlhelp/spread/DateFormats.htm

     

     

    Inside rapidminer, you can also have a quick reference list from "nominal to date" operator.

     

    Some standard date formats are listed there

     

    date.PNG

     

    Cheers,

    YY

  • felix_w
    felix_w New Altair Community Member

    That's really helpful! Now I get, it's simply because my date (May) has 3 letters, that is why I need three M's (MMM), right?! Would have been quite streight forward..