Five Stars

Talend Job, Runs with CURDATE() Doesn't get current date when ran with Windows Task Schedule

HI, I have a Job that runs and grabs the last 7 days of data - emails it to me. When ran in TOS it is corrected. When I create the Bat file and run with Windows Task Scheduler it uses the last day it was ran in Talend as the Current Date and not the actual date ran. 

 

Any suggestions on how to get the CURDATE  in the mysql import query to use the actual date the task schedule is running?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Fifteen Stars

Re: Talend Job, Runs with CURDATE() Doesn't get current date when ran with Windows Task Schedule

I don't see why CurDate in mySQL would be affected by this. Maybe you could show us your code? But this solution will work for you. In a tJava at the beginning of your job, place this code....

globalMap.put("Date", routines.TalendDate.formatDate("yyyy-MM-dd", routines.TalendDate.getCurrentDate()));

This will store a correctly formatted (for mySQL) Date as String in the globalMap. Then in your MySQL query you can use it in the Where Clause like this....

"Select
Your,
Column,
Data
From Your.Table
Where yourDateColumn < '" +((String)globalMap.get("Date"))+"'"
Rilhia Solutions
4 REPLIES
Moderator

Re: Talend Job, Runs with CURDATE() Doesn't get current date when ran with Windows Task Schedule

Hello,

Does your job work perfectly fine when you run your job script .bat file directly in cmd without using Windows Task Scheduler ?

Best regards

Sabrina

--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Five Stars

Re: Talend Job, Runs with CURDATE() Doesn't get current date when ran with Windows Task Schedule

cmd does use the actual curdate - so it works through there! How do I get that to run a scheduled basis? 

Fifteen Stars

Re: Talend Job, Runs with CURDATE() Doesn't get current date when ran with Windows Task Schedule

I don't see why CurDate in mySQL would be affected by this. Maybe you could show us your code? But this solution will work for you. In a tJava at the beginning of your job, place this code....

globalMap.put("Date", routines.TalendDate.formatDate("yyyy-MM-dd", routines.TalendDate.getCurrentDate()));

This will store a correctly formatted (for mySQL) Date as String in the globalMap. Then in your MySQL query you can use it in the Where Clause like this....

"Select
Your,
Column,
Data
From Your.Table
Where yourDateColumn < '" +((String)globalMap.get("Date"))+"'"
Rilhia Solutions
Five Stars

Re: Talend Job, Runs with CURDATE() Doesn't get current date when ran with Windows Task Schedule

My code used CURDATE directly in the sql. By doing the Java date, we are able to fins a solution that works! thank you for your assistance!