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

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] Difference between two dates excluding weekends

Hi,
I have a scenario where I have two dates in two columns(Create date and As of date) which comes in a file.
I have to find the number of working days in between these two dates where the count excludes the weekends(Saturday and Sunday).
Appreciate if I get the code to be written in Talend open Studio.
Thanks
Pradhab
Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Hello,
Maybe you can create a routine and implement a method in this routine doing what you want.
An example of method could be :
public class NumberOfDays {
   static int day_of_week;
   public static Integer getNumberOfDaysWorked(java.util.Date beginDate,java.util.Date endDate){
  Integer val = 0;
  while (beginDate.before(endDate)){
  day_of_week=TalendDate.getPartOfDate("DAY_OF_WEEK", beginDate);
  if(day_of_week != 1 && day_of_week != 7){// 1 is for Sunday and 7 is for Saturday
  val = val+1;
  }
  beginDate = TalendDate.addDate(beginDate, 1, "dd");
  }
  return val;
  }
}

After that you call this method in a Tmap.
I hope it can help you.

View solution in original post

3 Replies
Anonymous
Not applicable
Author

Hello,
Maybe you can create a routine and implement a method in this routine doing what you want.
An example of method could be :
public class NumberOfDays {
   static int day_of_week;
   public static Integer getNumberOfDaysWorked(java.util.Date beginDate,java.util.Date endDate){
  Integer val = 0;
  while (beginDate.before(endDate)){
  day_of_week=TalendDate.getPartOfDate("DAY_OF_WEEK", beginDate);
  if(day_of_week != 1 && day_of_week != 7){// 1 is for Sunday and 7 is for Saturday
  val = val+1;
  }
  beginDate = TalendDate.addDate(beginDate, 1, "dd");
  }
  return val;
  }
}

After that you call this method in a Tmap.
I hope it can help you.
Anonymous
Not applicable
Author

Thanks you so much for the code. I created a routine and implemented the method in it and called the method in the tmap in Talend. It worked as expected.
Thanks
Pradhab
Anonymous
Not applicable
Author

You are welcome. 0683p000009MA9p.png
I think you can mark this post as 'resolved'.