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?
4 REPLIES
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.