Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number of days between two dates [duplicate]

Tags:

date

c#

I have two dates:

Jun 26 2012 12:13AM and Jul 31 2012 12:54PM

I need to compare this two dates and extract Number of days(difference) between them

like image 649
user1502952 Avatar asked Aug 02 '12 06:08

user1502952


People also ask

Which function returns the number of days passed between two dates?

Using the DATEDIF Function DATEDIF function (derived from Date Difference) also allows you to quickly get the number of days between two dates.

How do I get the number of days between two dates in Python?

return int(years / 4) - int(years / 100) + int(years / 400) # This function will return number of days between two given dates.


1 Answers

Use TimeSpan

TimeSpan difference = dateTime1 - dateTime2;

difference.TotalDays will give you number of days

var days = difference.TotalDays;
like image 71
Habib Avatar answered Oct 09 '22 00:10

Habib