Hi..
How to get the difference between two dates using C#.NET web application in form of days?

If anybody knows plz help me..Itz very urgent.

Re: Difference between two dates on C#.NET 80 80
DateTime dt = Convert.ToDateTime(txtDate1.Text); //mm/dd/yyyy
DateTime dt1 = Convert.ToDateTime(txtDate2.Text);//mm/dd/yyyy
TimeSpan ts = dt.Subtract(dt1);
diffDate.Text  = ts.Days.ToString() ;
Re: Difference between two dates on C#.NET 80 80

Use this code ,It may help you
DateTime sdate = Convert.ToDateTime(txtFromDate.Value);
DateTime edate = Convert.ToDateTime(txtToDate.Value);
TimeSpan ts = edate - sdate;
int days = ts.Days;

Re: Difference between two dates on C#.NET 80 80

How i get date difference and showing it in datalist

Re: Difference between two dates on C#.NET 80 80

Thanks for sharing the information regarding calculating the date difference. It was very useful.

Re: Difference between two dates on C#.NET 80 80

What are the different date formats that we can use in Asp.Net ?

Re: Difference between two dates on C#.NET 80 80

use these mththods

DateTime newDate = new DateTime(2000, 5, 1);

System.TimeSpan diff = secondDate.Subtract(firstDate);

String diff2 = (secondDate - firstDate).TotalDays.ToString();

full source C# Date Difference

Re: Difference between two dates on C#.NET 80 80
Doubting

Can i use DateTime different = date1 - date2; instead of using TimeSpan data type?

Re: Difference between two dates on C#.NET 80 80

You can find like th following..

String diff2 = (secondDate - firstDate).TotalDays.ToString();

C# Date Differnce

Elvaris

Re: Difference between two dates on C#.NET 80 80

THANKS GEE

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.