I have a job that loads a CSV into a MySQL table. The field I am paring to a date using the t-map component has empty strings for a few of the records. When parsing the string to date, I need to convert those empty strings to the current date. I've tried this expression in the tmap component with no luck. My field name is "Payroll_Pay_Date" Here is the expression:
row1.Payroll_Pay_Date equals("")?TalendDate.getCurrentDate():TalendDate.parseDate("MM/dd/yyyy",row1.Payroll_Pay_date)
I've tried several itterations of this. Actually, what I really want to is to have the empty string be replaced with the "current date - 7 days" but I figure I would start with the above. Any advice would be much appreciated.
You could do this:
row1.Payroll_Pay_Date == null || row1.Payroll_Pay_Date.trim().isEmpty() ? TalendDate.getCurrentDate() : TalendDate.parseDate("MM/dd/yyyy",row1.Payroll_Pay_date)
Here I first test if the string is null or if it's empty or containing only whitespaces, in which case I return the current date. Otherwise I parse the date.
To get the current date minus 7 days, you could do:
TalendDate.addDate(TalendDate.getCurrentDate(), -7, "dd")