Skip to Content
0

Excluding weekends when calculating days between dates via C4C SDK

Sep 01, 2017 at 06:26 AM

130

avatar image

Hi,

We have added a new field via KUT in SAP C4C. The field is Due date. Now this due date field will be calculated on incident category field. (e.g: If incident category is x then due date will be 2 days + today's date, if incident category is y then due date will be 3 days + today's date).

I know how to do this, but how should i handle when the newly calculated date falls on a weekend. I want to calculate the correct date and it should exclude the weekends as well.

I am writing the code in Aftermodify event of the servicerequest BO via SDK.

regards,

Nikhil Moghe

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Benny Huang Sep 05, 2017 at 04:30 AM
1

Hi Nikhil,

At aftermodify event, refer to the code :

var days = 0;

var str_start_date = "20170301";
var str_end_date = "20170331";

var start_date = Date.ParseFromString(str_start_date);
var end_date = Date.ParseFromString(str_end_date);

while (start_date <= end_date)
{
var tmp_date = Date.ParseFromString(end_date.ToString());
var tmp_result = tmp_date.GetWeekday();

switch (tmp_result)
{
case 1,2,3,4,5
{
days = days + 1;
}
case 6,7
{
//weekend
}
}
end_date = end_date.SubtractDuration(Duration.ParseFromString("P1D"));
}

Best Regards,

Benny

Share
10 |10000 characters needed characters left characters exceeded
Nikhil Moghe Sep 07, 2017 at 06:42 AM
0

Hey Benny,

I just came to know that now we have to use the public holiday's as well.

Thanks for the info. Just wanted to ask you another question. Instead of using this logic can I use the C4C calendar to get the weekends as well as public holidays.

If we can use the calendar then which class should i use to fetch the calendar data.

Regards,

Nikhil Moghe

Share
10 |10000 characters needed characters left characters exceeded