Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
RP1629548713
Contributor II
Contributor II

Date subtraction in talend

Hi All,

I am trying to calculate age of a product.

For this i need to subtract the current date from initial date (creation _date) and result should be in months.

Can someone help me with the logic for this ? As diffdate is not working with the string data types .

Please suggest​

Labels (2)
5 Replies
gjeremy1617088143
Creator III
Creator III

Hi, if your date are in String data type you can do something like this:

 

TalendDate.diffDate(TalendDate.parseDate("yyyy-MM-dd",(String of Date1)), TalendDate.parseDate("yyyy-MM-dd",(String of Date2)), "MM")

 

date pattern have to correspond to the date pattern of your String eg: "yyyy-MM-dd" for 2021-12-31

Send me love and kudos

RP1629548713
Contributor II
Contributor II
Author

I need to subtract it from the current date .

The current date - creation_date ​

gjeremy1617088143
Creator III
Creator III

so replace TalendDate.parseDate("yyyy-MM-dd",(String of Date1)) by TalendDate.getCurrentDate()

RP1629548713
Contributor II
Contributor II
Author

Hi,

​​I tried implementing it ,but I get the following error :

Type mismatch: cannot convert from long to String

gjeremy1617088143
Creator III
Creator III

Yes it's because diffDate return a Long and it seems you expect a String so :

String.valueOf(TalendDate.diffDate(TalendDate.getCurrentDate(), TalendDate.parseDate("yyyy-MM-dd",(String of Date2)), "MM"))