How can i substract a 1 month to a example that is a date?
cdaponte
New Altair Community Member
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!!!
Thank you!!!
Tagged:
0
Best Answers
-
There are many ways to accomplish this in RapidMiner. If your attributes are defined as date/time types, then one way would be use the datediff function inside Generate Attributes and simply convert from milliseconds to months (and then potentially round that number in some way).
Another way would be to use Date to Numerical to get the month number of your date/time stamps and then do ordinary subtraction (with an adjustment to handle the possible negative values).
2 -
Hi,You could divide the MS by something like (30*24*60*60*1000) which is the total number of MS in 30 days.Hope this helps,
Ingo1
Answers
-
There are many ways to accomplish this in RapidMiner. If your attributes are defined as date/time types, then one way would be use the datediff function inside Generate Attributes and simply convert from milliseconds to months (and then potentially round that number in some way).
Another way would be to use Date to Numerical to get the month number of your date/time stamps and then do ordinary subtraction (with an adjustment to handle the possible negative values).
2 -
Perfect! And how can i convert from milliseconds to month?1
-
Hi,You could divide the MS by something like (30*24*60*60*1000) which is the total number of MS in 30 days.Hope this helps,
Ingo1 -
@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>
1