Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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;
}
}
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 🙂
Hi,
Thanks for your time, But I have already created a routine for my requirement called from tmap and it works fine.
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 🙂
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;
}
}
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 🙂
Please follow the steps to create a routine in the below link.This might help