The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here

How to get part of the date?

blatooblatoo Member Posts: 32 Contributor II
edited November 2018 in Help
I have an attribute "time" in a data set, which format is also date, its value is like "Mar 9, 2010 3:51:34 AM CET".

- I want to generate two new attributes, one is "day": for example: Mar 9, 2010

- the other is "hour": for example: 3:51:34 AM

So, I use the "Generate Attributes", but I don't know, how to write the expressions. I tried for date_get(date_get(time, DATE_UNIT_DAY)) for the first case, but I get just exactly the number 9, nothing else.

How can I get the part of the day and the exact time in the day?

Answers

  • Marco_BoeckMarco_Boeck Administrator, Moderator, Employee-RapidMiner, Member, University Professor Posts: 1,996 RM Engineering
    Hi,

    you're looking for these functions:

    date_str_custom(date, "MMM d, yyyy")
    date_str_custom(date, "hh:mm:ss a")
    Regards,
    Marco
  • blatooblatoo Member Posts: 32 Contributor II
    Hi Marco,

    thanks very much for the answer!

    Are there a detailed discription with examples about how to use the time functions?
  • Marco_BoeckMarco_Boeck Administrator, Moderator, Employee-RapidMiner, Member, University Professor Posts: 1,996 RM Engineering
    Hi,

    have a look here: http://docs.rapidminer.com/studio/operators/data_transformation/attribute_space_transformation/generation/generate_attributes.html

    From inside Studio you can get help by activating the "Help" view and selecting the operator you want help for.

    Regards,
    Marco
  • helena_ahmadihelena_ahmadi Member Posts: 2 Learner III

    Hi, 

     

    I was looking for the same solution, the only thing is I need to present the month as "Nov" and not "11".

    when I write 'date_str_custom(date, "yyyy/MM")' in generate new attribute operator I recieve the result as : 2017/11 but I need: 2017/Nov.

     

    Then How can we define the final presentation of month in this context? 

     

    Thanks and regards,

    Helena

  • Edin_KlapicEdin_Klapic Employee-RapidMiner, RMResearcher, Member Posts: 299 RM Data Scientist

    Hi @helena_ahmadi,

     

    A list of the available patterns can e.g. be found in the Help of the Operator Date to Nominal which is also available online on https://docs.rapidminer.com/latest/studio/operators/blending/attributes/types/date_to_nominal.html.

     

    In your case you just need to add a "M" to your expression leading to date_str_custom(date, "yyyy/MMM").

    In Generate Attributes you can also define which localization you want to use e.g. date_str_custom(date, "yyyy/MMM","us").

     

    Happy Mining,

    Edin

  • helena_ahmadihelena_ahmadi Member Posts: 2 Learner III

    Hi @Edin_Klapic,

    Thanks, it worked now. 

     

  • robinrobin Member Posts: 100 Guru

    Because I found this usefull when needing to generate date info, I thought I would put it here.

     

    Generating a date and inserting into a feed. 

     

    <?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="subprocess" compatibility="8.1.001" expanded="true" height="82" name=a"add date (2)" width="90" x="246" y="34">
    <process expanded="true">
    <operator activated="true" class="text:create_document" compatibility="8.1.000" expanded="true" height="68" name="open date (3)" width="90" x="514" y="34">
    <parameter key="text" value="&quot;content_date&quot;: &quot;"/>
    </operator>
    <operator activated="true" class="text:create_document" compatibility="8.1.000" expanded="true" height="68" name="close date (3)" width="90" x="514" y="289">
    <parameter key="text" value="&quot;,&#10;"/>
    </operator>
    <operator activated="true" class="generate_data_user_specification" compatibility="8.1.001" expanded="true" height="68" name="Generate Data by User Specification (2)" width="90" x="112" y="136">
    <list key="attribute_values">
    <parameter key="date_time" value="date_now()"/>
    </list>
    <list key="set_additional_roles"/>
    </operator>
    <operator activated="true" class="date_to_nominal" compatibility="8.1.001" expanded="true" height="82" name="Date to Nominal (2)" width="90" x="246" y="136">
    <parameter key="attribute_name" value="date_time"/>
    <parameter key="date_format" value="yyyy-MM-dd'T'HH:mm:ss.SSSZ"/>
    <parameter key="locale" value="English (South Africa)"/>
    </operator>
    <operator activated="true" class="nominal_to_text" compatibility="8.1.001" expanded="true" height="82" name="Nominal to Text (2)" width="90" x="380" y="136">
    <parameter key="attribute_filter_type" value="single"/>
    <parameter key="attribute" value="date_time"/>
    </operator>
    <operator activated="true" class="text:data_to_documents" compatibility="8.1.000" expanded="true" height="68" name="Data to Documents (3)" width="90" x="514" y="136">
    <list key="specify_weights"/>
    </operator>
    <operator activated="true" class="text:combine_documents" compatibility="8.1.000" expanded="true" height="124" name="Combine Documents (4)" width="90" x="715" y="136"/>
    <connect from_op="open date (3)" from_port="output" to_op="Combine Documents (4)" to_port="documents 1"/>
    <connect from_op="close date (3)" from_port="output" to_op="Combine Documents (4)" to_port="documents 3"/>
    <connect from_op="Generate Data by User Specification (2)" from_port="output" to_op="Date to Nominal (2)" to_port="example set input"/>
    <connect from_op="Date to Nominal (2)" from_port="example set output" to_op="Nominal to Text (2)" to_port="example set input"/>
    <connect from_op="Nominal to Text (2)" from_port="example set output" to_op="Data to Documents (3)" to_port="example set"/>
    <connect from_op="Data to Documents (3)" from_port="documents" to_op="Combine Documents (4)" to_port="documents 2"/>
    <connect from_op="Combine Documents (4)" from_port="document" to_port="out 1"/>
    <portSpacing port="source_in 1" spacing="0"/>
    <portSpacing port="sink_out 1" spacing="0"/>
    <portSpacing port="sink_out 2" spacing="0"/>
    </process>
    </operator>
    <connect from_op="add date (2)" from_port="out 1" 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>
Sign In or Register to comment.