DATE_UNIT_WEEK seems incorrect

sCapatinasCapatina Member Posts: 17 Contributor II
edited November 2018 in Help
Good day!

I am trying to get the correct week number out of a date attribute, but it seems the function date_get([created_at],DATE_UNIT_WEEK) is not giving the correct week number.

For example today (Jan 12) we are in Week 2 of 2016.

This is the rapidminer output:

created_at                                      year        week  month  day
Tue Jan 12 16:14:55 EST 2016 2016.0 3.0   1.0     12.0
Sun Jan 10 00:22:34 EST 2016 2016.0 3.0   1.0     10.0
Sat Jan 09 23:59:08 EST 2016 2016.0 2.0   1.0       9.0

I have tried with a couple if functions to correct the mistake, but it seems the week ranges themselves are not accurate.

What is the best way to solve this?




  • Options
    Marco_BoeckMarco_Boeck Administrator, Moderator, Employee, Member, University Professor Posts: 1,996 RM Engineering

    the value returned depends on the locale. If I explicitly specify the locale for Germany, it will return 2.
    So if you change your function to

    date_get([created_at],DATE_UNIT_WEEK, "de", "Europe/Berlin")
    you will get the expected value of 2.

  • Options
    sCapatinasCapatina Member Posts: 17 Contributor II
    That worked, thank you!
  • Options
    lghansselghansse Member Posts: 18 Contributor II



    I've a similar problem and tried to remedy it with the suggestion above, but it doesn't seem to work. I generated a variabel 'date' that is just a calander for the year 2010, and a variable week which has to indicate the week of the year. However, the first week starts at 26/12/2010 and not at 01/01/2010. I suppose this is because rapidminer starts weeks at sunday and 01/01/2010 is a friday, so week 2 starts at sunday 03/01/2010 and so on. Any idea how I can change so that the weeks start to count at 01/01/2010?


    This is the XML:

    <?xml version="1.0" encoding="UTF-8"?><process version="7.5.003">
    <operator activated="true" class="process" compatibility="7.5.003" expanded="true" name="Process">
    <process expanded="true">
    <operator activated="true" class="operator_toolbox:generate_univariate_series" compatibility="0.7.000" expanded="true" height="68" name="Generate Univariate Series" width="90" x="112" y="34">
    <parameter key="data_type" value="DATE_TIME"/>
    <parameter key="attribute_name" value="date"/>
    <parameter key="startdate" value="2010-01-01 01:00:00"/>
    <parameter key="enddate" value="2010-12-31 01:00:00"/>
    <parameter key="intervaltype" value="DAY"/>
    <operator activated="true" class="generate_attributes" compatibility="7.5.003" expanded="true" height="82" name="Generate Attributes" width="90" x="246" y="34">
    <list key="function_descriptions">
    <parameter key="week" value="date_get(date, DATE_UNIT_WEEK, &quot;be&quot;, &quot;Europe/Brussels&quot;)"/>
    <connect from_op="Generate Univariate Series" from_port="output" to_op="Generate Attributes" to_port="example set input"/>
    <connect from_op="Generate Attributes" 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"/>

  • Options
    sgenzersgenzer Administrator, Moderator, Employee, RapidMiner Certified Analyst, Community Manager, Member, University Professor, PM Moderator Posts: 2,959 Community Manager

    hello @lghansse - ah yes, the old "week of the year" question.  I was working on this last month.  It's actually not an innocent question and has to do with when the 1st week of the year is defined.  It's a LONG story but in short, you're going to have to do some manipulation to get the "week" attribute the way you want it.  Here's some light reading on the topic: 







  • Options
    lghansselghansse Member Posts: 18 Contributor II

    Wow, never heard of it before, but thanks! 

Sign In or Register to comment.