add one year to current year

  • Thread starter Thread starter Claudia Fong
  • Start date Start date
C

Claudia Fong

Hi,

I need to add one to the current year so the year would be 2006.

I'm using the code below and I put this code before the
InitializeComponent()

next_year and current_year are declare as int.

current_year = DateTime.Now.Year;
next_year = current_year + 1; ---> the result of this is still 2005
instead of 2006

Is there any problem with this code?? It should work... :(

Cheers!

Claudi
 
The code snippet looks fine. Just to be sure, I tried it in a simple console
application. So something else must be going on. There's a part of me that
would print out DateTime.Now, just to be sure that the computer's time has
been set properly.
 
Hello,
You should write it like this:
DateTime currentDate = DateTime.Now;
DateTime nextYearDate = currentDate.AddYears(1);

HTH. Cheers.
Maqsood Ahmed [MCP,C#]
Kolachi Advanced Technologies
http://www.kolachi.net
 
Back
Top