Rahul Patel Rahul Patel - 9 months ago 42
SQL Question

how to get date diiference while using datetime in asp.net

i dont know how to fetch start date and eddate in two textbox , i just entered two date in this textbox.

DateTime firstday = TextBox2.Text;
DateTime secondday = TextBox3.Text;

i am new in this field. i am working with asp.net.in my database there is two datetime field, and i want to get exact difference of day between that two.


first you need to convert that to textbox value to datetime and then you can found difference betwween those two. i will give you example.

DateTime firstday = Convert.ToDateTime(TextBox2.Text);
DateTime secondday = Convert.ToDateTime(TextBox3.Text);
double Day = (secondday - firstday).TotalDays;
Label2.Text = Day.ToString();