Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

how to get odd saturday in a month in c#

int year = 2016; // 366 days in 2016 because leap year
DateTime yearStart = new DateTime(year, 1, 1);
int daysInYear = (yearStart.AddYears(1) - yearStart).Days; // 366
var oddSaturdays = Enumerable.Range(0, daysInYear)
    .Select(day => yearStart.AddDays(day))
    .Where(date => date.Day % 2 == 1 && date.DayOfWeek == DayOfWeek.Saturday);

foreach (DateTime oddSaturday in oddSaturdays)
{ 
    // ...
    string sql = string.Format("INSERT INTO {0}.[WEEKEND] ([DATE],[DAYNAME]) VALUES (@DATE, @DAYNAME)", schemaname);
    using (var cmd = new SqlCommand(sql, con))
    {
        cmd.Parameters.Add("@DATE", SqlDbType.Date).Value = oddSaturday;
        cmd.Parameters.Add("@DAYNAME", SqlDbType.VarChar).Value = oddSaturday.DayOfWeek.ToString();
        int inserted = cmd.ExecuteNonQuery();
    }
    // ...
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: string in char list f# 
Csharp :: c# fileinfo filename without extension 
Csharp :: how to make soft body OBJECT in unity 
Csharp :: startup c# class winform 
Csharp :: two question marks together mean in C# 
Csharp :: unity call function after delay 
Csharp :: c# list double min max 
Csharp :: What is the best way to lock cache in asp.net? 
Csharp :: c# console.writeline next line 
Csharp :: c# fill values of child from parent 
Csharp :: c# wtssendmessage 
Csharp :: c# get Full Exception message if InnerException is not NULL 
Csharp :: How to do a comment in c# 
Csharp :: string extentions not working 
Csharp :: how to take previous record in linq c# 
Csharp :: runner dotnet trace inside docker container 
Csharp :: translate english to spanish 
Csharp :: how to handle array getter setter in c# of string type 
Csharp :: c# compare 2 binary files 
Csharp :: card caption 
Csharp :: unity matchinfo 
Csharp :: split nullable in c# 
Csharp :: creating weighted graph in c# 
Csharp :: c# list add and return 
Csharp :: Show Form on Second Monitor 
Csharp :: advance C# tricks and hits 
Csharp :: C# program to implement the Quadratic Formula 
Csharp :: boucle C# 
Csharp :: get local position unity 
Csharp :: embergene 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =