c# - How to add a number of days to a Date while skipping weekends and other holidays and start day is weekend or holiday -


below code calculates number of workdays added , if end date falls on holidays/weekends, shift date next day.
but code on assumption start date not on weekends/holidays.

i want code works if start date falls on weekend/holiday.

please note code posted elenasofea on 17 jun'13 not able comment on asking new question.
reference: how add number of days date while skipping weekends , other holidays

static datetime calculatefuturedate(datetime fromdate, int numberofworkdays,                                    icollection<datetime> holidays) {     var futuredate = fromdate;     (var = 0; < numberofworkdays; i++ )     {         if (futuredate.dayofweek == dayofweek.saturday           || futuredate.dayofweek == dayofweek.sunday          || (holidays != null && holidays.contains(futuredate)))         {             futuredate = futuredate.adddays(1);             numberofworkdays++;         }         else         {             futuredate = futuredate.adddays(1);         }     }     while(futuredate.dayofweek == dayofweek.saturday           || futuredate.dayofweek == dayofweek.sunday          || (holidays != null && holidays.contains(futuredate)))     {         futuredate = futuredate.adddays(1);     }     return futuredate; } 

try pass date input, such method validates check whether saturday or sunday

public static boolean isvalidatesundayorsaturday(string date) throws exception {          calendar calendar = calendar.getinstance();              if (date != null) {              calendar.settime(getdate(date,null));             int day = calendar.get(calendar.day_of_week);              if (day == calendar.sunday || day == calendar.saturday) {                 return true;             }          }         return false;     } 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -