Difference Dates Calculation
<p>I   have  three  textboxes, <code>StartTextbox</code>, <code>EndTextBox</code>, and <code>Textbox3</code>, where <code>Textbox3</code> contains <code>No of Month</code>. Now I want difference of start date and end date to be checked     against <code>No of Month</code>.</p>

<p>Here is the custom validation function:</p>

<pre><code>protected void ValidateDuration(object sender, ServerValidateEventArgs e)
{
    DateTime start = DateTime.Parse(StartTextBox.Text);
    DateTime end = DateTime.Parse(EndTextBox.Text);

    int months = (end.Month - start.Month) + 12 * (end.Year - start.Year);

    e.IsValid = months &lt;= TextBox3;
}
</code></pre>
