Question

How do I get the values of days (Sunday to Saturday) using DatePart in .NET? My idea is, if it is a Saturday or Sunday, I have to skip the loop.

Was it helpful?

Solution 2

So for a date range you could try:

for(var curr_date = fromDate; curr_date <= toDate; curr_date.AddDays(1))
{
  if (curr_date.DayOfWeek == DayOfWeek.Saturday || 
      curr_date.DayOfWeek == DayOfWeek.Sunday)
  {
     break;
  }      
}

OTHER TIPS

while (true)
{
   if (DateTime.Now.DayOfWeek == DayOfWeek.Saturday
       || DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
   {
       break;
   }
}
 string s = DateTime.Now.DayOfWeek.ToString();
    if (s == "Saturday")
    {
      //Your code     
    }

you can add your condition appropriate to the application

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top