How can I calculate difference between two dates in C#?

$0
=
$0
+
$0
No specific Bitcoin Bounty has been announced by author. Still, anyone could send Bitcoin Tips to those who provide a good answer.
0

I have seen some answers for Java, Javascript, and PHP, but nothing for C#. So, how one might calculate the number of days between two dates in C#?

Thanks.

1 Answer - total earned - 0 BTC ($0 USD)

1
=
0
=
$0
Everyone, even non-registered users could send Bitcoin Tips to YOU if they are inspired by your answer!

Assuming StartDate and EndDate are of type DateTime:

 DateTime date1 = DateTime.Now;
 DateTime date2 = DateTime.Now.AddDays(-5);
(date1 - date2).TotalDays

Advanced code:

DateTime d1 = DateTime.Now;
DateTime d2 = DateTime.Now.AddDays(-1);

TimeSpan t = d1 - d2;
double Difference = t.TotalDays;

I hope it helped you!

SEND BITCOIN TIPS
0

Post Answer


Will Bitcoin Tipping become a new Internet Culture?


Please share our story! THANK YOU!