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

Six 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?

 


Accepted Solutions
Community Manager

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"))+"'"

All 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.
Six 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? 

Community Manager

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"))+"'"
Six 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! 

What’s New for Talend Spring ’19

Watch the recorded webinar!

Watch Now

Agile Data lakes & Analytics

Accelerate your data lake projects with an agile approach

Watch

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch