Warning: Cannot modify header information - headers already sent by (output started at /home/www/talendforge.org/forum/viewtopic.php:1) in /home/www/talendforge.org/forum/header.php on line 14

Warning: Cannot modify header information - headers already sent by (output started at /home/www/talendforge.org/forum/viewtopic.php:1) in /home/www/talendforge.org/forum/header.php on line 15

Warning: Cannot modify header information - headers already sent by (output started at /home/www/talendforge.org/forum/viewtopic.php:1) in /home/www/talendforge.org/forum/header.php on line 16

Warning: Cannot modify header information - headers already sent by (output started at /home/www/talendforge.org/forum/viewtopic.php:1) in /home/www/talendforge.org/forum/header.php on line 17

Warning: Cannot modify header information - headers already sent by (output started at /home/www/talendforge.org/forum/viewtopic.php:1) in /home/www/talendforge.org/forum/header.php on line 20
Using TalendDate addDate Method (Page 1) / Usage, Operation / Talend Community Forum
 

You are not logged in.

#1 2012-06-05 19:31:08

new talend user
Member
0 post

Using TalendDate addDate Method

Hi,

I'm trying to use the TalendDate addDate method. I need to be able to add 90 days to any given date to properly generate a date that many days from now. Is the addDate method the proper way to do this? If so, how do I go about using it. I can't seem to make sense of the Help section within the program and I haven't been able to find any useful instructions online.

Thanks

#2 2012-06-05 19:39:57

phobucket
Member
146 posts

Re: Using TalendDate addDate Method

Hi and welcome to the forum,

Put your input file into a tMap component, on the output side of the tMap component.
In the expression field on the ouput side of the tMap, use TalendDate.addDate(row1.MyDate, 90, "dd")

You will have to replace row1.MyDate with the name of your date field.

Good luck,
Ben

Offline

#3 2012-06-05 19:46:03

new talend user
Member
0 post

Re: Using TalendDate addDate Method

Thanks for your quick reply. Do I need to include the date pattern? If so, how should it be shown? My input value is a string.

Also, what will the output data type be? Can I keep it as a string?

Thanks

#4 2012-06-05 19:57:11

new talend user
Member
0 post

Re: Using TalendDate addDate Method

I've tried doing this but when I run the test in the expression builder with a legitimate example value, I get "Exception in thread "main" java.lang.Error: Unresolved compilation problem:"

TalendDate.addDate(row1.TransactionDate,"yyyyMMdd",90,"dd")

#5 2012-06-05 20:05:20

phobucket
Member
146 posts

Re: Using TalendDate addDate Method

You need to drop the "yyyyMMdd".

Try this: TalendDate.addDate(row1.TransactionDate,90,"dd")

Offline

#6 2012-06-05 20:12:41

new talend user
Member
0 post

Re: Using TalendDate addDate Method

I've tried dropping what you suggested but I get an error message: "The method addDate(Date, int, String) in the type TalendDate is not applicable for the arguments (String, int, String)"

My input is a string of format yyyyMMdd. I'd like my output to either be a date type or a string.

And this is my code now as you suggested: TalendDate.addDate(row1.TransactionDate,90,"dd")

The expression builder still throws a flag. Perhaps it would work if I actually did a run but I'm not ready with the rest of my job yet to do that.

Thanks for your help. I just don't know what is going wrong.

#7 2012-06-05 20:28:02

phobucket
Member
146 posts

Re: Using TalendDate addDate Method

Ok.  row1.TransactionDate is currently formatted as a String.  You will need to change that to a date.  You can either do that at the point of import, or use nest the parseDate function inside the adddate.

TalendDate.addDate(TalendDate.parseDate("yyyyMMdd", row1.TransactionDate),90,"dd")

Offline

#8 2012-06-05 21:49:00

new talend user
Member
0 post

Re: Using TalendDate addDate Method

I've tried getting it all set up and I gave my job a test run. Any ideas now?

Exception in component tMap_1_TMAP_IN
java.lang.RuntimeException: java.text.ParseException: Unparseable date: ""
    at routines.TalendDate.parseDate(TalendDate.java:643)
    at bonusme.transaction_processing_0_1.Transaction_Processing.tFileList_1Process(Transaction_Processing.java:3472)
    at bonusme.transaction_processing_0_1.Transaction_Processing.tMysqlConnection_1Process(Transaction_Processing.java:522)
    at bonusme.transaction_processing_0_1.Transaction_Processing.runJobInTOS(Transaction_Processing.java:7978)
    at bonusme.transaction_processing_0_1.Transaction_Processing.main(Transaction_Processing.java:7839)
Caused by: java.text.ParseException: Unparseable date: ""
    at java.text.DateFormat.parse(DateFormat.java:337)
    at routines.TalendDate.parseDate(TalendDate.java:641)
    ... 4 more

Board footer