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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Extract year from a date

Hi all, 

I want extract a year from a date by using this function :

Integer.parseInt(TalendDate.formatDate("yyyy",consultation.Date)) 

I find a java error.

 

Please i request your help to resolve this.

 

Thank you.

Labels (3)
1 Solution

Accepted Solutions
TRF
Champion II
Champion II

I say try to replace "yyyy" by "YEAR".
If it doesn't work,share the whole job design.

View solution in original post

14 Replies
TRF
Champion II
Champion II

Hi,
What is the error message?
Is it compilation error or a runtime error?
What is the datatype for consultation.Date?
Anonymous
Not applicable
Author

Thank you for this speed.

i receive this error message:

Exception in component tMap_1
java.lang.NullPointerException
at java.util.Calendar.setTime(Unknown Source)
at java.text.SimpleDateFormat.format(Unknown Source)
at java.text.SimpleDateFormat.format(Unknown Source)
at java.text.DateFormat.format(Unknown Source)
at routines.TalendDate.formatDate(TalendDate.java:135)
at testcubeolap.extract_year_0_1.extract_year.tFileInputExcel_1Process(extract_year.java:1206)
at testcubeolap.extract_year_0_1.extract_year.runJobInTOS(extract_year.java:1612)
at testcubeolap.extract_year_0_1.extract_year.main(extract_year.java:1469)

 

my date format is "dd-MM-yyyy"

Thank you .

TRF
Champion II
Champion II

This error will arrive as soon as a record contains a null value for consultation.Date. Try to replace with the following:
consultation.Date != null ?
Integer.parseInt(TalendDate.formatDate("yyyy",consultation.Date)) : null
Anonymous
Not applicable
Author

Thank you , 

but here i receive this :

Exception in component tMap_1
java.lang.NullPointerException
at testcubeolap.extract_year_0_1.extract_year.tFileInputExcel_1Process(extract_year.java:1208)
at testcubeolap.extract_year_0_1.extract_year.runJobInTOS(extract_year.java:1613)
at testcubeolap.extract_year_0_1.extract_year.main(extract_year.java:1470)

 

Furthermore, i'm sure that i don't have a null value on my source table.

what i do now, i'm blocked here.

 

 

 

TRF
Champion II
Champion II

Share your tMap, related expression and schema definition
Anonymous
Not applicable
Author

Thank you.


year.png
Anonymous
Not applicable
Author

i tried this function :

(consultation.Date != null) ?
TalendDate.getPartOfDate("yyyy",consultation.Date) : 100

and i find a lot of 0 and the last value is 100.

do you say something about?

 

Thank you.

 

TRF
Champion II
Champion II

I say try to replace "yyyy" by "YEAR".
If it doesn't work,share the whole job design.
Anonymous
Not applicable
Author

 OK, 

i try with this function:

TalendDate.getPartOfDate("YEAR",consultation.Date) 

 

i receive the good value but :

1- the last value is 0

2- i find error on red and i can visualise what are.

Thank you


ERROR.png
JOB.png