When I Enter start date like 1/9/2017 for 12 month so how to find the end date as per calculation of 12 months after.
Asked
Active
Viewed 52 times
-2
-
2`date.AddYears(1)`? – Quality Catalyst Sep 01 '17 at 07:12
-
If someone enters `29/2/2016` what do *you* consider to be twelve months later? Similar questions arise for `28/2/2015` and `1/3/2015`. What rules do you want to use here? – Damien_The_Unbeliever Sep 01 '17 at 07:14
-
Also, check this: https://stackoverflow.com/questions/29362830/c-sharp-not-adding-a-year-with-addyears1 – Quality Catalyst Sep 01 '17 at 07:15
-
1`System.DateTime` has plenty of options for this. Please explain why they do not satisfy your needs. – oerkelens Sep 01 '17 at 07:17
-
i want to do agreement fot 11 months but when i start agreement for todays date but i can not find end date. i find manually but i want to do in programmatically. – sandeep kanade Sep 01 '17 at 07:26
-
Please establish some context while asking a question. you have thrown a question here which hardly makes any sense. What do you mean by "When I Enter start date like 1/9/2017 for 12 month" – Gurpreet Sep 01 '17 at 12:54
1 Answers
0
You could do it like this assuming that 1/9/2017 is dd/mm/yyyy. If not then just switch 1 and 9 around.
var startDate = new DateTime(2017, 9, 1);
var endDate = startDate.AddMonths(12);

Maritim
- 2,111
- 4
- 29
- 59