Declare a date constant

Highlighted
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?
Highlighted
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
Highlighted
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
Highlighted
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
Highlighted
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 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