Extract year from a date

Five Stars

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.


Accepted Solutions
Forteen Stars TRF
Forteen Stars

Re: Extract year from a date

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

TRF
Forteen Stars TRF
Forteen Stars

Re: Extract year from a date

The rule is to have 1 question per topic.
Please, accept the preceding then open a new one.

TRF

All Replies
Forteen Stars TRF
Forteen Stars

Re: Extract year from a date

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

TRF
Five Stars

Re: Extract year from a date

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 .

Forteen Stars TRF
Forteen Stars

Re: Extract year from a date

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

TRF
Five Stars

Re: Extract year from a date

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.

 

 

 

Forteen Stars TRF
Forteen Stars

Re: Extract year from a date

Share your tMap, related expression and schema definition

TRF
Five Stars

Re: Extract year from a date

Thank you.

Five Stars

Re: Extract year from a date

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.

 

Forteen Stars TRF
Forteen Stars

Re: Extract year from a date

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

TRF
Five Stars

Re: Extract year from a date

 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

Forteen Stars TRF
Forteen Stars

Re: Extract year from a date

Once again you need to protect yourself again null value for consultation.Date

TRF
Five Stars

Re: Extract year from a date

Thank you for your generosity.

Please, now i need another help.

I have  2 tables "consultation" et "beneficiaire" and i want count the number of consultations per beneficiary.

Unfortunately, I do not know how to express this in talend.

 

Thank you for all.

Five Stars

Re: Extract year from a date

Please what do you think about this :

(consultation.idBeneficiaire == beneficiaire.idBeneficiaire ) ?
NombreTotal = NombreTotal+1

 

thank you.

Forteen Stars TRF
Forteen Stars

Re: Extract year from a date

The rule is to have 1 question per topic.
Please, accept the preceding then open a new one.

TRF
Forteen Stars TRF
Forteen Stars

Re: Extract year from a date

The rule is to have 1 question per topic.
Please, accept the preceding then open a new one.

TRF