cancel
Showing results for 
Search instead for 
Did you mean: 

Excluding weekends when calculating days between dates via C4C SDK

0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member200995
Contributor

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

0 Kudos

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