473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

add one year to current year



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.developersdex.com ***
Nov 17 '05 #1
2 18604
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.objectsharp.com/blogs/bruce
"Claudia Fong" wrote:


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.developersdex.com ***

Nov 17 '05 #2
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

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dave | last post by:
Hi, Can anyone tell me a simple way of inserting some sort of code into a Dreamweaver template (it goes at the bottom of the page in Copyright info) that will cause the current year to be...
3
by: jannoergaard | last post by:
Hi I want to write a function that can return a sum for a given date range. The same function should be able to return the sum for the same period year before. Let me give an example: The...
5
by: mchlle | last post by:
I have a form that allows the user to choose and open a report from a drop down box based on the semester they choose from an option box. Option 1-3 are Spring, Summer and Fall and each semester...
5
by: Jimmy | last post by:
How do I set the default value of a text box (date/time) to 1/1/Current Year... i.e 1/1/2006 this year, 1/1/2007 next year?
4
by: john | last post by:
I have an unbound field in which I would like to show january 1 of the current year like this 01-01-2007. I tried this code but it doesn't work: =dateserial(Year(date()),1,1) Can someone help me...
8
by: sanika1507 | last post by:
Hi all how to write this 01/01/ and whatever year is coming as current year -1....in an SQL query .i want it to write it in a stored proc... using SQL server 2000. Thanks in advance . .
6
by: abhishekbrave | last post by:
i have created following drop down box for displaying year... i want to populate the drop down box upto current year.. and need to write a java script for this .. any pointers in this regard will be...
2
by: clloyd | last post by:
I have a form that when you hit a command button it moves the current year value (could be three years prior) to a previous year field. I need code to insert the current year in the current year...
5
by: tbeers | last post by:
Good morning. I am running a timecard program in Access 2007 and it seems that the users have trouble entering the correct year when entering the date in the date field. Date field entry format...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.