add one year to current year

add one year to current year

Post by Claudia Fo » Wed, 08 Jun 2005 11:43:34



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

*** Sent via Developersdex http://www.yqcomputer.com/ ***
 
 
 

add one year to current year

Post by QnJ1Y2UgSm » Wed, 08 Jun 2005 13:06:02

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.
--
Bruce Johnson [C# MVP]
http://www.yqcomputer.com/

 
 
 

add one year to current year

Post by Maqsood Ah » Wed, 08 Jun 2005 13:58:28

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.yqcomputer.com/

*** Sent via Developersdex http://www.yqcomputer.com/ ***