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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] Concatenate strings to date

Hi,
Being new to TOS I'm still struggling with the beginners lack of experience. I'll be happy if somebody could help me on the following problem:
I am trying to create a date with the following values (fields) available:
month (string)
year (string)
additionally I'll add '01' for the first day of a month, since there is no need any other day in a month
In the expression editor of the tMap component the date should been assembled like this:
TalendDate.parseDate("yyyy-MM-dd",fieldYear+"-"+fieldMonth+"-01")
When I run the job I get the following error:
connected
java.lang.NumberFormatException: For input string: "1-"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at routines.system.FastDateParser$DateParser.parse(FastDateParser.java:129)
at java.text.DateFormat.parse(Unknown Source)
at routines.TalendDate.parseDate(TalendDate.java:850)
at routines.TalendDate.parseDate(TalendDate.java:808)
at rd_data_personal.lohnexp_0_1.lohnExp.tDBInput_1Process(lohnExp.java:1509)
at rd_data_personal.lohnexp_0_1.lohnExp.runJobInTOS(lohnExp.java:1963)
at rd_data_personal.lohnexp_0_1.lohnExp.main(lohnExp.java:1822)
Exception in component tMap_1
java.lang.RuntimeException: java.text.ParseException: Unparseable date: "2014-1-01"
at routines.TalendDate.parseDate(TalendDate.java:864)
at routines.TalendDate.parseDate(TalendDate.java:808)
at rd_data_personal.lohnexp_0_1.lohnExp.tDBInput_1Process(lohnExp.java:1509)
at rd_data_personal.lohnexp_0_1.lohnExp.runJobInTOS(lohnExp.java:1963)
at rd_data_personal.lohnexp_0_1.lohnExp.main(lohnExp.java:1822)
Caused by: java.text.ParseException: Unparseable date: "2014-1-01"
at java.text.DateFormat.parse(Unknown Source)
at routines.TalendDate.parseDate(TalendDate.java:850)
... 4 more
disconnected
Job lohnExp ended at 15:13 10/06/2014.

Thanks for any suggestion on how to solve this,
Felix
Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Hi,
Your month string should have lengh of 2 characters.
So if it is less than 10 you should pad with 0 at the left before parsing the string into Date.
Here is how to padd your month with "0" when less than 10:
Integer.valueOf(fieldMonth)<10 ? "0"+fieldMonth: fieldMonth
So you use the result of this ternary expression in your parsedate function.
Regards

View solution in original post

4 Replies
Anonymous
Not applicable
Author

Hi,
u can display yours String in the console with tLogRow component or tJavaRow component with System.ou.println(fieldYear);
i guess that value of fieldYear is 1 instead of 2014
Anonymous
Not applicable
Author

Hi,
Your month string should have lengh of 2 characters.
So if it is less than 10 you should pad with 0 at the left before parsing the string into Date.
Here is how to padd your month with "0" when less than 10:
Integer.valueOf(fieldMonth)<10 ? "0"+fieldMonth: fieldMonth
So you use the result of this ternary expression in your parsedate function.
Regards
Anonymous
Not applicable
Author

Thanks guys for the quick reply :-).
@sofbar: your code just did the job, it was the missing 0 in the month field.
Regards,
Felix
Anonymous
Not applicable
Author

You are welcome Felix
BR