Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

This[^] will help to get you started as might this[^].
 
Share this answer
 
Assuming that you add whole date only and ignore thing like time changes, something similar to this should do:
C#
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);
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900