I have a start date and an end date.
Start Date: 14/06/2018
End Date: 14/06/2020
The user will fill in how many reviews they want to do for the 2 years.
I have calculated the date difference in weeks for the start and end date.
So, in this case, it would be 105 weeks.
Let's say the user wants to do a review every 10 weeks.
So, I divide the 105 weeks / how many reviews they want to do which = 10.5.
I would like to insert a record into my database 10 times and have the dates spread equally between the start date and end date.
How would I do this?
UPDATE EDIT:
double test;
test = (double)Convert.ToInt32(hdnUIOID.Value) / (double)Convert.ToInt32(txtEvery.Text);
string constr = ConfigurationManager.ConnectionStrings["EBSLIVE"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand();
var startDate = new DateTime(2018, 6, 14);
var endDate = new DateTime(2020, 6, 14);
var howManyReviews = test;
// Calculate how many days between revisions
var days = (endDate - startDate).Days / (howManyReviews - 1);
// Calculate dates of revisions
var revisionDates = new List<DateTime>() { startDate };
while ((startDate = startDate.AddDays(days)) < endDate)
revisionDates.Add(startDate);
for (int i = 0; i < test; i++)
{
try
{
string strStudentStatus = "INSERT INTO EF_REVIEWDATES(REVIEW_DATE) VALUES "+ string.Join(",", Convert.ToDateTime(revisionDates.Select(dt => "('" + dt.ToString("yyyy-MM-dd") + "')")));
cmd.CommandText = strStudentStatus.ToString();
cmd.Parameters.Clear();
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
string errorMsg = "Error in Insert";
errorMsg += ex.Message;
throw new System.Exception(errorMsg);
}
finally
{
con.Close();
Response.Redirect(Request.RawUrl);
}
}