I have some code where i wanna end up with 2 lists. Startings and endings.
They contain start date of month and enddate of month.
These 2 lists i wanna put in an object variable so i can use the object in a foreachloop container in ssis,and loop through each row with startofmonth and endofmonthdates (variables: min and max) - But i dont know how to
Here are my codes:
String s = "2013-01-01";
String b = "2014-01-01";
using (SqlConnection connection = new SqlConnection("Server=localhost;Initial Catalog=LegOgSpass;Integrated Security=SSPI;Application Name=SQLNCLI11.1"))
{
connection.Open();
string query = "select mindate,maxdate from dbo.dates";
using (SqlCommand command = new SqlCommand(query, connection))
{
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
s = reader.GetDateTime(0).ToShortDateString();
b = reader.GetDateTime(1).ToShortDateString();
//minDate.Add(reader.GetDateTime(0));
//maxDate.Add(reader.GetDateTime(1));
}
}
}
}
DateTime startdate = Convert.ToDateTime(s);
DateTime enddate = Convert.ToDateTime(b);
DateTime parseDate;
List<DateTime> minDate = new List<DateTime>();
List<DateTime> maxDate = new List<DateTime>();
List<DateTime> startings = new List<DateTime>();
List<DateTime> endings = new List<DateTime>();
startings.Add(startdate);
parseDate = startdate.AddMonths(1);
while (parseDate.Day != 1)
parseDate = parseDate.AddDays(-1);
parseDate = parseDate.AddDays(-1);
endings.Add(parseDate);
while (parseDate < enddate)
{
parseDate = parseDate.AddDays(1);
startings.Add(parseDate);
parseDate = parseDate.AddMonths(1);
parseDate = parseDate.AddDays(-1);
endings.Add(parseDate);
}
endings[endings.Count() - 1] = enddate;
for (var x = 0; x < startings.Count; x++)
{
Dts.Variables["test"].Value = x;
}
Dts.TaskResult = (int)ScriptResults.Success;