Extract year from a date

Highlighted
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
Sixteen Stars TRF
Sixteen 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

View solution in original post

Sixteen Stars TRF
Sixteen 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

View solution in original post


All Replies
Sixteen Stars TRF
Sixteen 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 .

Sixteen Stars TRF
Sixteen 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.

 

 

 

Sixteen Stars TRF
Sixteen 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.

 

Sixteen Stars TRF
Sixteen 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

View solution in original post

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

Sixteen Stars TRF
Sixteen 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.

Sixteen Stars TRF
Sixteen 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

View solution in original post

Sixteen Stars TRF
Sixteen 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

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog