🦉🦉   WOOT WOOT!   RAPIDMINER WISDOM 2020 EARLY BIRD REGISTRATION ENDS FRIDAY DEC 13!   REGISTER NOW!   🦉🦉

How can i substract a 1 month to a example that is a date?

cdapontecdaponte Member Posts: 29  Maven
I´m using generate attributes operator and i want to create an attribute that if a date es 1 month before a certain day it returns me "1", and if it is 2 month before it returns me "2", and so on till "6". How can i do this? 

Thank you!!!

Best Answers

Answers

  • cdapontecdaponte Member Posts: 29  Maven
    Perfect! And how can i convert from milliseconds to month? 
    Tghadially
  • kaymankayman Member Posts: 416   Unicorn
    @cdaponte,  You could use the date_get function for this (under generate attributes). This allows you the get the month value for the  current date and the 'older' date, and as these are numeric (0 to 11) you could simple calculate the difference (in months) 

    As in attached example : I used two (generated) dates, one is now and the other is like 2 months ago (50 days difference). this gives a number for each month (be aware that for some strange reason month numbers start with 0 for January instead of 1)

    <?xml version="1.0" encoding="UTF-8"?><process version="9.3.001">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="9.3.001" expanded="true" name="Process">
        <parameter key="logverbosity" value="init"/>
        <parameter key="random_seed" value="2001"/>
        <parameter key="send_mail" value="never"/>
        <parameter key="notification_email" value=""/>
        <parameter key="process_duration_for_mail" value="30"/>
        <parameter key="encoding" value="UTF-8"/>
        <process expanded="true">
          <operator activated="true" class="generate_macro" compatibility="9.3.001" expanded="true" height="82" name="Generate Macro" width="90" x="313" y="34">
            <list key="function_descriptions">
              <parameter key="MonthNow" value="date_get(date_now(),DATE_UNIT_MONTH)+1"/>
              <parameter key="MonthOld" value="date_get(date_add(date_now(),-50,DATE_UNIT_DAY),DATE_UNIT_MONTH)+1"/>
            </list>
          </operator>
          <connect from_port="input 1" to_op="Generate Macro" to_port="through 1"/>
          <connect from_op="Generate Macro" from_port="through 1" to_port="result 1"/>
          <portSpacing port="source_input 1" spacing="0"/>
          <portSpacing port="source_input 2" spacing="0"/>
          <portSpacing port="sink_result 1" spacing="0"/>
          <portSpacing port="sink_result 2" spacing="0"/>
          <description align="center" color="yellow" colored="false" height="50" resized="true" width="177" x="268" y="134">January = month 0</description>
        </process>
      </operator>
    </process>
    


    Tghadially
Sign In or Register to comment.