Calculate data time

G

Grey

how can i get the difference and sum when I pass two dates.e.g.
2004/7/20 - 2004/7/3 = 17

2004/7/20 + 1 = 20047/21 or
2004/7/31 + 1 = 2004/8/1

Million thanks
 
M

Martin Dechev

Hi,

I suggest you read the documentation for System.DateTime and System.TimeSpan
structures:

http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDateTimeClassTopic.asp
http://msdn.microsoft.com/library/en-US/cpref/html/frlrfSystemTimeSpanClassTopic.asp

The Subtraction operator when applied on two DateTime structures results in
a TimeSpan instance that represents the difference. Then use the Days
property of this structure to get the number of whole days represented by
the instance:

[C#]
TimeSpan span1 = date1 - date2;
int days = span1.Days;

For the second part of your question - you should be using the method
AddDays on a DateTime instance:

DateTime date2 = date1.AddDays(1);

Hope this helps
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top