PDA

View Full Version : how can i create a week- or month number from a date



kettle_anonymous
02-09-2006, 01:49 AM
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

kettle_anonymous
02-09-2006, 06:29 AM
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

MattCasters
02-09-2006, 12:34 PM
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

kettle_anonymous
02-10-2006, 12:08 AM
Thanks Matt,

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