How would you create a validate statement that shows a message to the user if they enter a value that is 5 years or older than the current date, I have the checking of format for the date if its entered correctly.
Currently I have this to valid the format that the user inputs the two dates:
private void CalBtn_Click(object sender, EventArgs e)
{
// Definate the DateTime var for the formula below.
try
{
DateTime arrival;
DateTime departure;
// show how many days between the Departure day and the current day. (On Calculate Btn Click)
arrival = Convert.ToDateTime(arrivalTxb.Text); //Convert arrival date to text.
departure = Convert.ToDateTime(departTxb.Text); //Convert departure date to text.
TimeSpan nighttotal = departure - arrival; // departure minus arrival = number of days
int nights = nighttotal.Days;
nnightTxb.Text = nights.ToString(); // show on Number of Nights text box.
// Calculate price of total days requests. Price is a static $115
int subtotal = nights * 115; // Total = nights (number of days staying above) times 115 (price per night).
totalTxb.Text = subtotal.ToString("c"); // show total in Total Price textbox formatted.
}
catch (FormatException)
{
MessageBox.Show("Invalid format. Please try again!", "Entry Error");
}
}
Thanks for any help or hints.