What is the easist way to caclulate the difference in days between two dates?

R

Ryan

I would prefer not to use a reference to VB... just want an elegant way to
calculate days between two dates.

For example, 2004/12/31 and 2005/01/01 would show an elapsed time in days of
1.
 
N

nevin

You could create a TimeSpan with one date taken away from the other (you
could use each ones Ticks property) and then the TimeSpan will give you the
difference in Days, Hours etc

Look up TimeSpan and you will find lots to fine tune what you need.
 
C

Chris R. Timmons

I would prefer not to use a reference to VB... just want an
elegant way to calculate days between two dates.

For example, 2004/12/31 and 2005/01/01 would show an elapsed
time in days of 1.

Ryan

DateTime start = new DateTime(2004, 12, 31);
DateTime end = new DateTime(2005, 1, 1);
TimeSpan ts = end - start;
int elapsedDays = ts.Days;
 

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

Top