If you subtract two
DateTime
data types, then you get a
TimeSpan
as a result. You are then trying to convert this into an int, which is not possible. Depending on what you are trying to do you need do do this:
int n;
if (startingdate.Value > endingdate.Value)
{
n = (int)(startingdate.Value - endingdate.Value).TotalSeconds;
txtduration.Text = n.ToString();
}
else
n = (int)(endingdate.Value - startingdate.Value).TotalSeconds;
txtduration.Text = n.ToString();
This assumes you are trying to find the total duration in one of those formats
Hope this helps