Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What is the way to get the next working day in c# please?
I would like to pass in a date and if the passed in date is friday then it returns monday, if passed in date is tuesday then return date is wednesday and so forth. So it should return the next working day. Do I just have to add if statements to get the return value?
Thanks
Posted

Have a look at this CP article: Business Dates Calculation[^].
 
Share this answer
 
Business Dates Calculation[^] is a article that should surely help you out.

If not, this[^] would be another good read.
 
Share this answer
 
v2
C#
public DateTime FindBusinessDay(1, DateTime fromDate)
       {
           //This is used to count the number of business days

           int businessDays = 0;

           int noOfDays = numberOfBusinessDays;

           for (int i = 1; i <= numberOfBusinessDays; i++)
           {
               if (IsWeekEnd(fromDate))
                   numberOfBusinessDays++;
               else
                   businessDays++;
               if (businessDays != noOfDays)
               {
                   fromDate = fromDate.AddDays(1);
               }

               else
               {
                   break;
               }
           }

           return fromDate;
       }



It will return date from that you can get day
 
Share this answer
 
v2
yes if depending upon day names only u want to display the working days then simple if stmts are enough.
 
Share this answer
 
C#
string todaysDate, nextDay;
         // for todays date write this code
          todaysDate = System.DateTime.Now.ToString();

          // for next day
          nextDay = Convert.ToString(System.DateTime.Now.AddDays(1));
 
Share this answer
 

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