Click here to Skip to main content
15,902,114 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello everyone

I have this problem

I need sum the day + 1 and I don't know how to do that.

The result should be:

Day + 1/Month/Year

Thanks
Posted

C#
DateTime today = DateTime.Now.Date;
DateTime tomorrow = today.AddDays(1);
 
Share this answer
 
v3
Comments
TANicox 18-Feb-11 13:01pm    
Ok,
I had already tried but the problem with this is:
I don't want to show me the time.
Sergey Alexandrovich Kryukov 18-Feb-11 13:12pm    
Right, 5, but see my more general Answer.
--SA
Espen Harlinn 18-Feb-11 14:01pm    
Good answer - he asked about how to add one day to a datetime - My 5
Nish Nishant 18-Feb-11 14:09pm    
Thanks Espen.
C#
DateTime myDateTime = DateTime.Now;
DateTime newDateTime = myDateTime.AddDays(1);


If only you had read the documentation[^] you might have found such an elementary thing for yourself.
 
Share this answer
 
Comments
TANicox 18-Feb-11 13:02pm    
Ok, I had already tried but the problem with this is: I don't want to show me the time.
Henry Minute 18-Feb-11 13:07pm    
There is no separate Date structure/class in .NET. If it is a matter of displaying just the Date part then use the newDate.ToShortDate() or newDate.ToLongDate() methods which both return a string of just the date part.

If there is a different problem, then please edit your question to try to describe it.
Sergey Alexandrovich Kryukov 18-Feb-11 13:15pm    
The name "DateTime" for methods and properties is very common and pretty silly.
There is no such thing as "date" in nature, essentially "date" is also time.
So conceptually "DateTime" is just "Time", but the class encapsulate methods of working with calendar, similar thing is with TimeSpan.
--SA
Henry Minute 18-Feb-11 13:17pm    
At least it is fairly descriptive of what it does. Not always true of .NET classes.
TANicox 18-Feb-11 13:10pm    
The problem is this:

MessageBox.Show(DateTime.Now.AddDays(1).ToString());

Result:
19/02/2011 17:09
I don't want the time
More generally, you can add/subtract System.TimeSpan to cover any thinkable periods of time.

C#
DateTime before = DateTime.Now;
//wait a bit
DateTime after = DateTime.Now;

TimeSpan duration = after - before;
TimeSpan extraTime = new TimeSpan(2, 12, 21); //2:12:21 hours:minutes:seconds

duration += extraTime; //defined add/subtract for TimeSpan

before += duration; //defined add/subtract for DateTime and TimeSpan (must be right operand)
before = before - duration;

//will not compile, not defined, of course:
//duration = duration - after; 


—SA
 
Share this answer
 
Comments
Espen Harlinn 18-Feb-11 13:59pm    
Good instructions, a 5 :)
Sergey Alexandrovich Kryukov 18-Feb-11 14:18pm    
Thank you.
--SA

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