Hitachi Vantara Pentaho Community Forums
Results 1 to 4 of 4

Thread: how can i create a week- or month number from a date

  1. #1
    Join Date
    Sep 2005
    Posts
    1,403

    Default how can i create a week- or month number from a date

    I cannot get this to work with a javascript calculation.
    I used the example in the manual and I ended up with this line of code:


    week = datum.Clone().dat2str("w").getInteger();



    where datum is a date field and i defined week as an integer.
    When I test the script it says everything is OK.
    But when i run it I get:
    'Unexpected Error in '-' :java.lang.IndexOutOfBoundException: Index :0, Size:0



    I also tried:
    var d=datum.getDate();
    week = d.Clone().dat2str("w").getInteger();



    then it gives me an error when i test it:
    'Undefined is not a function at line 2'












    Thanks



    Remco

  2. #2
    Join Date
    Sep 2005
    Posts
    1,403

    Default RE: how can i create a week- or month number from a date

    OK, did some more testing and there is an other problem.
    If the (mysql) input table has a field of type date then:


    week = datum.Clone().dat2str("w").getInteger();



    works fine.



    If I have a field datum of type 'string' and i use the "select values" transformation step to convert it to a date it doesn't work, so i think there is the real problem.



    Regards,



    Remco

  3. #3
    Join Date
    Nov 1999
    Posts
    9,729

    Default RE: how can i create a week- or month number from a date

    Hallo Remco,

    Ofcourse, you could use the "Week Of Year" function in Calculator. Please see the sample Date dimension creator transformation in the web repository or elsewhere in this forum.

    Also, be careful with implicit conversions from String to Date: it uses a fixed conversion mask of "yyyy/MM/dd HH:mm:ss.SSS"
    It's slightly different from the ISO standard mask "yyyy/MM/dd'T'HH:mm:ss", but hey, who uses this anyway?

    So in short, I strongly disagree that there is a real problem. You're saying "convert a string to a date, and try to guess how to do it"? I don't think that this is the way to go. Better use the str2dat() function using a javascript.

    Hey thanks for the feedback, it helps us see where the actual problem is: getting Kettle to do what you want.
    In this case, the construction of a series of steps dedicated to simplifying data type conversions is under way.

    All the best,

    Matt

  4. #4
    Join Date
    Sep 2005
    Posts
    1,403

    Default RE: how can i create a week- or month number from a date

    Thanks Matt,

    I agree with you, this was not a real problem of kettle.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.