One Star

Get yesterday's date and convert it to a string in yyyy-MM-dd format?

Hi, I would like to get yesterday's date and convert it to a string in the format 'yyyy-mm-dd'
Here is what I have tried in a tJavaRow component:
outputFile.row = StringHandling.EREPLACE(tJava.row,"d",TalendDate.addDate(TalendDate.getCurrentDate(),-1,"dd").toString());

This is working but gives an unformatted date
I have looked at the tJava component but don't understand how it is meant to work
See my job design attached
Thank You Smiley Happy
2 REPLIES
Seventeen Stars

Re: Get yesterday's date and convert it to a string in yyyy-MM-dd format?

I would not do this in a tJavaRow. Use a tMap and set for the column you want this expression:
TalendDate.formatDate("yyyy-MM-dd", TalendDate.addDate(TalendDate.getCurrentDate(), -1, "dd"))
One Star

Re: Get yesterday's date and convert it to a string in yyyy-MM-dd format?

Hi, thank You this code worked Smiley Happy