Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

extract year from date type variable

Hello,
I m using TOS3.10 / java under windows xp and I wonder how I can extract the year part of a date or datatime type?
I will use it in an expression filter of a Tmap. From several tables i want to make a join but not all rows of the input table are suitable for the join.
Can someone help me, since i do not know anything of java.
Michel
Labels (3)
13 Replies
Anonymous
Not applicable
Author

You can get the year using the Talend Date routines :
TalendDate.formatDate("yyyy",rowX.myDate)
Anonymous
Not applicable
Author

Thanks bcourtine for your respond,
I put your suggestion in the expression filter of the tMap but it returned with an error message which says:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The left-hand side of an assignment must be a variable
See below a screenshot of my tMap design.
Can you please give your reaction. Can you perhaps explain to me what went wrong?
Thanks in advance,
Michel
Anonymous
Not applicable
Author

Hello
There should be double '=',eg:
TalendDate.formatDate("yyyy",row1.date)=="2009"
Best regards

shong
Anonymous
Not applicable
Author

Hello Shong,
thanks for the reply, it works(which means no error message) but I 've no output. And I'm sure the yearpart 2009 or 2999 is in the table.
The date 2999-01-01 can be the value of the variable scd_end which is in the script:
TalendDate.formatDate("yyyy",row1.Scd_end)=="2009"
I doubt if the value of the TalendDate.formatDate("yyyy",row1.Scd_end) is a character value. It is for sure that the value is not the same as 2009 or 2999.
I hoped the following took place: "2009" = "2009" (so that particular row was selected).
Can you explain a solution.
Regards,
Michel
Anonymous
Not applicable
Author

Hello
The method TalendDate.formatDate return a string, so you can try the following expresson:
TalendDate.formatDate("yyyy",row1.Scd_end).equals("2009")
Best regards
shong
Anonymous
Not applicable
Author

Shong,
thank you very much for your help, it works now! One more question, I've submit several question related to TOD, but no answer. Do you know why? Can you inform a colleque of you for me please? I would very much appreciate that.
Thanks in advance,
Michel
Anonymous
Not applicable
Author

Hi all,
I have the same problem like micoppoolse, but in my case i want to get year of the current date.
I do so something like this, but it don't work.
TalendDate.formatDate("yyyy",TalendDate.getCurrentDate())

So may somebody help me please?
Thank you.
Anonymous
Not applicable
Author

Here is for you IDEMBELE : 
TalendDate.getDate("CCYY")
Anonymous
Not applicable
Author

Hi mathis,
Thank you, but this code    
TalendDate.getDate("CCYY")

     return a boolean
So to resolve the problem, i use this code
TalendDate.formatDate("yyyy",new Date())