14,636,013 members
Rate this:
See more:
Hi,

I want to calculate the end date based on Atrt date and duration. Here I want to avoid the Saturday and Sunday and I want to calculate remaining days. How to do this one in Javascript and also in C#. Example the Duration is 7 and start date is 29/06/2012
Then the answer should come as 08/07/2012 It should avoid the Saturday and Sunday.

Posted
Updated 29-Jun-12 12:37pm
v2

Rate this:

## Solution 1

This[^] will help to get you started as might this[^].
Rate this:

## Solution 2

Assuming that you add whole date only and ignore thing like time changes, something similar to this should do:
```int daysTillStaturday = (int)DayOfWeek.Saturday - (int)startDate.DayOfWeek;
if (durationInDays < daysTillStaturday)

int remainingDays = durationInDays - daysTillStaturday;

// Skip first weekend and an extra one for each 5 days.
int weekendsCount = 1 + (remainingDays / 5);

// Compute final date by adding extra weekend days...
return startDate.AddDays(durationInDays + 2 * weekendsCount);```
v2