Reload

DateTime Suite Samples

DateDifferenceValidator

The DateDifferenceValidator compares two dates and performs an operation to determine if the dates are separated by the choosen number of days (Difference).

Remarks

The DateDifferenceValidator is similar to the DateCompareValidator, but varies in that you are comparing against a difference in the number of days between two dates.

A DateDifferenceValidator calculates the number of days between two dates and compares against a fixed value (.Difference). A DateCompareValidator compares two dates against each other.

The following example demonstrates how to use the DateDifferenceValidator and validate that the End Date must be 7 Days after the Start Date.

Example

Start Date:

End Date:

    

Code

<%@ Page Language="C#" %>
<%@ Register Assembly="BasicFrame.WebControls.BasicDatePicker" Namespace="BasicFrame.WebControls" TagPrefix="BDP" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>DateDifferenceValidator</title>
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.bdpStartDate.SelectedDate = DateTime.Today;
                this.bdpEndDate.SelectedDate = DateTime.Today.AddDays(7);
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <h4>Example</h4>
        <p>Start Date:<br />
            <bdp:basicdatepicker id="bdpStartDate" runat="server" />
        </p>
        <p>End Date:<br />
            <bdp:basicdatepicker id="bdpEndDate" runat="server" />
            &nbsp;&nbsp;
            <bdp:datedifferencevalidator 
                id="DateDifferenceValidator1" 
                runat="server" 
                controltocompare="bdpEndDate"
                controltovalidate="bdpStartDate" 
                difference="7" 
                errormessage="End Date must be 7 days after Start Date"
                operator="Equal">
             </bdp:datedifferencevalidator>
        </p>
        <p><asp:Button ID="Button1" runat="server" Text="Button" /></p>
    </form>
</body>
</html>