I have this code here that I'm using to print the number of days between two dates. After the user enters the dates in 2 text boxes on my form, I have a third text box that displays the amount of days. For example: 1st text box: 1/2/2020 | 2nd text box: 1/10/2020 | 3rd textbox: 8.00:00:00. In the third box I just want the number of days I don't want it in that time format. I understand that's what TimeSpan does but is there a way to format it so I just get 8 in the text box? I went through the properties for the text box but I couldn't find anything to format it. Is TimeSpan the wrong thing to use in this case?
C#:
private void btnCalculate_Click(object sender, EventArgs e)
{
DateTime arrive = DateTime.Parse(txtArrivalDate.Text);
DateTime depart = DateTime.Parse(txtDepartureDate.Text);
TimeSpan span = depart - arrive;
txtDays.Text = span.ToString();
}
Last edited: