Click here to Skip to main content
15,900,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
let me give an example :the date of beginning of a contract is: 1/7/2007 and the period of contract is 13 years what is the code in window form visual studio 2008 do we need to use for getting the date of the end of the contract on the 30/6/2020 ?? thx for your help.
Posted
Updated 21-Oct-11 7:47am
v2

1 solution

By reading about the DateTime struct[^]... :rolleyes:
C#
// Constructor using year, month, day.
DateTime d = new DateTime(2007, 1, 7);
// Add 13 years and assign the result to your date.
// Dates are immutable, like Strings.
d = d.AddYears(13);
// d now holds the original date + 13 years.

Not sure if your month is 7 and day is 1 or vice versa. Depends on your country.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 21-Oct-11 13:58pm    
The second date should clear your doubts: 30/6/2020
And don't forget to subtract one day, else the end date would be 01/07/2020 where it should be 30/06/2020.
Sander Rossel 21-Oct-11 14:46pm    
Indeed, very good point. Read over that detail ;)
devildx2050 21-Oct-11 14:39pm    
genrally yyyy-MM-dd format is preferred

DateTime d = new DateTime(2007, 1, 7);

in this case
Sander Rossel 21-Oct-11 14:47pm    
Yes, and as Manfred mentioned, don't forget to subtract a day.
In example above:
d = d.AddDays(-1);
Should do the trick :)
Don't forget to accept the answer that helped you so others will know you've been helped! Thank you :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900