How to get part of the date?
- 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
-
Hi,
you're looking for these functions:
Regards,
date_str_custom(date, "MMM d, yyyy")
date_str_custom(date, "hh:mm:ss a")
Marco0 -
Hi Marco,
thanks very much for the answer!
Are there a detailed discription with examples about how to use the time functions?0 -
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,
Marco0 -
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
0 -
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
1 -
1
-
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=""content_date": ""/>
</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="", "/>
</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>1