Declare a date constant

One Star

Declare a date constant

I have defined a Repository Context Variable as a Date datatype -- I intend to use this Context Variable in multiple jobs.
I am looking for the correct Java syntax to set this Date-type variable, but I don't know the syntax to set a date constant.
varCutoffDate = "2006-01-01" ;

The above code throws the error "cannot convert string to date"
How do I set a date variable in a tJava component?
Community Manager

Re: Declare a date constant

Hello
You need to parse the string to Date using the method:TalendDate.parseDate(String pattern, String dateString) provided by Talend.
context.date=TalendDate.parseDate("yyyy-MM-dd","2006-01-01");

Here date is the variable name, and its data type is Date.
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Declare a date constant

could anybody tell me how to parse a string in a date when you use perl instead of java
One Star

Re: Declare a date constant

Hi,
what would you like to do? Perl is (nearly) typeless so you do not have to parse dates.
Bye
Volker
One Star

Re: Declare a date constant

You need to parse the string to Date using the method:TalendDate.parseDate(String pattern, String dateString) provided by Talend.

Thanks. I discovered this method for declaring date constants:
SimpleDateFormat sdf = new SimpleDateFormat ( "yyyy-MM-dd" ) ;
context.varCutoffDate = sdf.parse("2006-01-01") ;

... but the Talend function should make it easier.

2019 GARNER 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

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Agile Data lakes & Analytics

Accelerate your data lake projects with an agile approach

Watch