Click here to Skip to main content
15,898,374 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, may i know if i have a date which is Friday. Then how do i check within the next 4 days if there is Saturday or Sunday?(by right it should have...) thks..

C#
string datetime = txtEffectiveDate.Text;

          var dt = DateTime.Parse(datetime).DayOfWeek;
          if (dt == DayOfWeek.Friday)
          {

          }
Posted
Comments
phil.o 3-Mar-14 2:45am    
Not clear at all. PLease rephrase your question; as it is, I cannot figure out what is your issue.
[no name] 3-Mar-14 3:05am    
refer this and do it manually http://www.sql-server-helper.com/tips/date-formats.aspx

here is a sample code
C#
DateTime dt = DateTime.Now;
            
            int range = 4;
            int offCount = 0;
            for (int i = 1; i <= range; i++)
            {
                if (dt.AddDays(i).DayOfWeek == DayOfWeek.Saturday || dt.AddDays(i).DayOfWeek == DayOfWeek.Sunday)
                    offCount++;
            }
 
Share this answer
 
v2
Comments
Ankur\m/ 3-Mar-14 4:31am    
I guess that is what the OP is looking for.
Well, if current date falls on Friday, next two dates will always be Saturday and Sunday. Am I missing something here?
 
Share this answer
 
Comments
Jamie888 3-Mar-14 2:48am    
yes u r right
Vedat Ozan Oner 3-Mar-14 2:50am    
so? :)
Jamie888 3-Mar-14 2:53am    
therefore i need to the system to determine if i entered friday and also the date range(eg. 4 days), then the system will prompt a message to tell me that i have 2 days off.
dan!sh 3-Mar-14 2:54am    
OK, so what is the problem here?
Jamie888 3-Mar-14 2:58am    
i need to know how can i code for the date range checking part...as the following scenario:
Day entered: Friday
Range: 4
then the system will check for me there r Saturday n Sunday(eg. You have 2 days off.)
the system will check from friday inclusive until monday which covered saturday n sunday.thks

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