Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi friends,


I am using gridview in that I have one bound field and 3 textbox template fields like this
------------------------------------------------------------- ---------
phase      Duration(weeks)    SrartDate         EndDate 
 
-----------------------------------------------------------------------

out side of gridview I have field: working days in a week:
ex: 5 0r 6

If I enter 1 or 1.5 week in Duration textbox , start Date : 12-05-2017 and if total working days in a week: 5 based on this values remove sturdays and sundays and find and display
End Date in gridview.

if working days in a week 6 days remove only sundays and find EndDate and display it in gridview.

Example:
If we Consider duration as 1 week,Working days in a week 6

then after 12-05-2017 then remove sunday date from calculation and the final End Date should print

20-05-2017

how to achive this??

What I have tried:

I tried using Adddays Method to given date
Posted
Updated 5-May-17 2:36am
v2
Comments
Richard MacCutchan 5-May-17 7:29am    
So what is the problem?
prasanna204 5-May-17 7:31am    
how to get the end date based on mentioned scenarios?I need code help
Richard MacCutchan 5-May-17 7:49am    
Add the number of days to the start date.
[no name] 5-May-17 7:33am    
what have you tried? Update question by adding your code/scripts...
prasanna204 5-May-17 8:08am    
Duration(weeks)=1;nofofworkingdays(in a week)=5;
Datetime Dt=convert.Todatedime(txtStartDate.Text);
Date date=dt.AddDays(7);
how to exclude saturdays and sundays if any caluculate based on nofofworking days

1 solution

Add the number of days and check the week day afterwards (add one or two days for Sunday and Saturday):
C#
// Add number of days
dt.AddDays(weeks * 7);
// Choose Monday if end date is Sunday
if (dt.DayOfWeek == DayOfWeek.Sunday)
    dt.AddDays(1);
// Choose Monday if end date is Saturday and Saturday is not a working day
else if (workingDays < 6 && dt.DayOfWeek == DayOfWeek.Saturday)
    dt.AddDays(2);
 
Share this answer
 
Comments
Maciej Los 8-May-17 1:46am    
5ed!

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