Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
vikramk
Creator II
Creator II

code for creating Routine

Hi,

 

I have scenario where I have to get date difference between start date and end date, and there is a string column with Segment where I will get two values ex: xyz, zxy, and if the segment is xyz then the date difference should exclude sunday, saturday and if the segment value is zxy then it should exclude only sunday. Can any one help with the code in creating a routine for this

Labels (3)
1 Solution

Accepted Solutions
vikramk
Creator II
Creator II
Author

Below is the code for DateDiff excluding Saturday and Sunday, works fine for my requirement

 

public class days {

static int day_of_week;
public static int getNumberOfDaysWorked(java.util.Date beginDate,java.util.Date endDate){
int 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;
}
}

View solution in original post

6 Replies
Anonymous
Not applicable

Hi,

 

    You cannot calculate the week day date difference with standard Talend date functions. You will have to create a custom routine and do a routine call from other Talend components.

 

    There are lot of solutions to identify the weekday count in stack overflow and you can use one of the methods provided from there.

 

https://stackoverflow.com/questions/4600034/calculate-number-of-weekdays-between-two-dates-in-java

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

vikramk
Creator II
Creator II
Author

Hi,

 

Thanks for your time, But I have already created a routine for my requirement called from tmap and it works fine.

Anonymous
Not applicable

Hi,

 

   If you could share the solution, it would be helpful for other Talend community members as a reference material.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

vikramk
Creator II
Creator II
Author

Below is the code for DateDiff excluding Saturday and Sunday, works fine for my requirement

 

public class days {

static int day_of_week;
public static int getNumberOfDaysWorked(java.util.Date beginDate,java.util.Date endDate){
int 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;
}
}

Anonymous
Not applicable

Hi,

 

    Appreciate for taking time to explain the details back to Talend community. Please also mark your post containing the solution as answer to the original query. This will help our community members during their search.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

st806p
Contributor
Contributor

Please follow the steps to create a routine in the below link.This might help

https://www.youtube.com/watch?v=_4xNimxfsCw