Click here to Skip to main content
15,902,198 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to add one year to a date but the new date is always wrong.

This is what I am doıng:
C#
newdate = date.Addyears(1);


date = 16.01.2010
I want the new date to be:
16.01.2011
but the new date always 16.00.2011.

What am I doing wrong here, I don't understand.

Thank you for your answer.
Posted
Updated 18-May-10 0:03am
v3
Comments
DaveAuld 18-May-10 6:10am    
Your question doesn't make sense because 00 as the month value is not valid and this cannot be returned by the addyears method as a result of a DateTime operations. Are you sure your not doing something else?

Providing your using standard DateTime operations there shouldn't be a problem;


C#
DateTime theDate = DateTime.Now;
DateTime yearInTheFuture = theDate.AddYears(1);
 
Share this answer
 
Comments
radix3 18-May-10 22:52pm    
Reason for my vote of 2
Perfectly explained
This works fine for me?
C#
DateTime date = new DateTime(2010, 01, 16);
DateTime futureDate = date.AddYears(1);
 
Share this answer
 

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