J
Justair07
Guest
Hello,
I have a WPF form where my users will enter a Project Name and a Start Date and End Date.
I would like to save a record for each month between the Start Date and End Date for the project.
So basically get the count of months between the two dates, and save a record for the project and the 1st day of each month for all month between the Start and End dates.
For example, user fills out form
Project_id: 123
Start Date: 7/10/2019
End Date: 5/15/2020
The code will add the following to the table:
Project_id SavingDate
123 7/1/2019
123 8/1/2019
123 9/1/2019
123 10/1/2019
123 11/1/2019
123 12/1/2019
123 1/1/2020
123 2/1/2020
123 3/1/2020
123 4/1/2020
123 5/1/2020
Even though they entered a Start and End date that are not on the 1st day of the month, the dates populated to the table are still the 1st day of the month.
Here is my code that saves the Project_id and the user selected StartDate. I know it's not much but I'm very new to C# and I have no clue how to get the count of months, iterate adding a record for the count of months in the month format.
pt_ProjectSaving NewForecastSaving = new pt_ProjectSaving
{
Project_id = id,
SavingDate = System.Convert.ToDateTime(dteStartDate.SelectedDate)
};
context.pt_ProjectSaving.Add(NewForecastSaving);
context.SaveChanges();
Any help is much appreciated.
- Justair
Continue reading...
I have a WPF form where my users will enter a Project Name and a Start Date and End Date.
I would like to save a record for each month between the Start Date and End Date for the project.
So basically get the count of months between the two dates, and save a record for the project and the 1st day of each month for all month between the Start and End dates.
For example, user fills out form
Project_id: 123
Start Date: 7/10/2019
End Date: 5/15/2020
The code will add the following to the table:
Project_id SavingDate
123 7/1/2019
123 8/1/2019
123 9/1/2019
123 10/1/2019
123 11/1/2019
123 12/1/2019
123 1/1/2020
123 2/1/2020
123 3/1/2020
123 4/1/2020
123 5/1/2020
Even though they entered a Start and End date that are not on the 1st day of the month, the dates populated to the table are still the 1st day of the month.
Here is my code that saves the Project_id and the user selected StartDate. I know it's not much but I'm very new to C# and I have no clue how to get the count of months, iterate adding a record for the count of months in the month format.
pt_ProjectSaving NewForecastSaving = new pt_ProjectSaving
{
Project_id = id,
SavingDate = System.Convert.ToDateTime(dteStartDate.SelectedDate)
};
context.pt_ProjectSaving.Add(NewForecastSaving);
context.SaveChanges();
Any help is much appreciated.
- Justair
Continue reading...