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.

Recommended Answers

All 9 Replies

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() ;

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;

How i get date difference and showing it in datalist

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

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

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

Doubting

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

You can find like th following..

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

C# Date Differnce

Elvaris

Be a part of the DaniWeb community

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