Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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?
Labels (3)
4 Replies
Anonymous
Not applicable
Author

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
_AnonymousUser
Specialist III
Specialist III

could anybody tell me how to parse a string in a date when you use perl instead of java
Anonymous
Not applicable
Author

Hi,
what would you like to do? Perl is (nearly) typeless so you do not have to parse dates.
Bye
Volker
Anonymous
Not applicable
Author

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.