Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
stagliaferri1640766615
Contributor II
Contributor II

Extract hour from date

Hello,

I am stuck at something it might be very simple.

I am defining a variable "currentDate" as :

Date currentDate = TalendDate.addDate(TalendDate.getCurrentDate(),- 3,"dd");

but I would like to set it as : if it is 8 am then it should be

TalendDate.addDate(TalendDate.getCurrentDate(),- 3,"dd") else TalendDate.addDate(TalendDate.getCurrentDate(),- 1,"dd")

Could someone help me please?

thanks a lot

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable

Hi

Try this on tJava:

     Calendar calendar = Calendar.getInstance();

   calendar.setTime(TalendDate.getCurrentDate());

   int hour = calendar.get(Calendar.HOUR_OF_DAY);

  

   if(hour==8){

context.currentDate=TalendDate.addDate(TalendDate.getCurrentDate(),- 3,"dd") 

}else{

context.currentDate=TalendDate.addDate(TalendDate.getCurrentDate(),- 1,"dd") 

}

 

Regards

Shong

 

 

 

View solution in original post

2 Replies
Anonymous
Not applicable

Hi

Try this on tJava:

     Calendar calendar = Calendar.getInstance();

   calendar.setTime(TalendDate.getCurrentDate());

   int hour = calendar.get(Calendar.HOUR_OF_DAY);

  

   if(hour==8){

context.currentDate=TalendDate.addDate(TalendDate.getCurrentDate(),- 3,"dd") 

}else{

context.currentDate=TalendDate.addDate(TalendDate.getCurrentDate(),- 1,"dd") 

}

 

Regards

Shong

 

 

 

stagliaferri1640766615
Contributor II
Contributor II
Author

it works!!

thank you very much Shong