Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
mshafeeq
Contributor III
Contributor III

context getcurrentdate

Hello All,

i designed a job to run on hourly basis on data -2 hours on timpalaload component

i created a context start_date as below

0695b00000htTLeAAM.png

and defined in tjavarow component as below

context.Start_Time = TalendDate.formatDate("yyyyMMdd",TalendDate.getCurrentDate());

System.out.println("/////////////////////////////////////");

System.out.println("Running Day = " + context.Start_Time);

and used in the query as below

where date_id = "+context.Start_Time+" and hour_id = ???????

my question and issue is , i want to use hour_id = extracted hour -2 and avoid switching day @12AM on job schedule 00

thanks for support

Labels (2)
4 Replies
anselmopeixoto
Partner - Creator III
Partner - Creator III

Hi @muhamd shafeeq​ 

 

To get current hour -2 you could use this code:

 

TalendDate.addDate(TalendDate.getCurrentDate(), -2, "HH")

 

The addDate method will return a Talend Date object, then you can format it according to your needs.

 

I hope this helps.

mshafeeq
Contributor III
Contributor III
Author

@Anselmo Peixoto​  @Shicong Hong​ 

 

hello ,

 

actually the issue is addDate function is retruing date value and i want to use it in sting format for the query

 

when i tested it query failed with below

Exception in the component tImpalaLoad_1:ParseException: Syntax error in line 1:

...dn) where date_id = Thu Jun 01 08:13:09 AST 2023 an

 

 

my context variable is working fine with current date but i want to add also filter on hour-2 and considering day switching@12AM

 

where date_id = "+context.Start_Time+" and hour_id = ???????

 

 

Lord-Vader
Contributor III
Contributor III

If im not wrong you have to format it so that it matches the type.

 

Try this :

TalendDate.formatDate("YYYY-MM-DD",TalendDate.addDate(TalendDate.getCurrentDate(), -2, "HH")) 

 

if you want something more/less like seconds etc, just change the pattern. And for your other problem, i dont understand what you want to do sorry.

anselmopeixoto
Partner - Creator III
Partner - Creator III

Hi @muhamd shafeeq​ 

 

You can use this:

 

TalendDate.formatDate("HH", TalendDate.addDate(TalendDate.getCurrentDate(), -2, "HH"))

 

The formatDate method takes a Date object and returns a String in the format you specify on the first argument, so you can use "HH" as argument to only return the hour from that Date object.