Click here to Skip to main content
14,636,013 members
Rate this:
Please Sign up or sign in to vote.
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.



Thanks in Advance
Posted
Updated 29-Jun-12 12:37pm
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

This[^] will help to get you started as might this[^].
   
Rate this:
Please Sign up or sign in to vote.

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)
    return startDate.AddDays(durationInDays);

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100