HI im trying to create a simple reservation form in visual studio that takes an arrival date and departure date, gets the duration and works out the cost of stay by multipling duration by £115 heres my code (the error pops up on line that begins “int nights = dateDiff” and says “Timespan cannot convert to int) thanks in advance for any help:
String arrival, departure;
arrival = textBox1.Text;
departure = textBox2.Text;
DateTime aDate, dDate;
aDate = new DateTime();
aDate = DateTime.ParseExact(arrival, "dd/mm/yyyy", null);
dDate = new DateTime();
dDate = DateTime.ParseExact(arrival, "dd/mm/yyyy", null);
TimeSpan dateDiff;
dateDiff = dDate.Subtract(aDate);
int nights = dateDiff;
textBox3.Text = ("" + nights);
textBox5.Text = ("£" + (nights * 115));
try
See MSDN. It might be helpful ro round (i.e.
(int) Math.Round(dateDiff.TotalDays)– see here.