Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi I need the Startdate and Enddate validation for the startdate and Enddate when both are in different format.In my case Startdate is in dd/MM/yyyy and EndDate is in MM/dd/yyyy

What I have tried:

ASP.NET
<pre><td align="left">
                                                    <asp:TextBox ID="txtstart" runat="server" OnTextChanged="txtstart_TextChanged" MaxLength="10" />
                                                    <asp:CalendarExtender ID="CalendarExtender1" CssClass="Cal_Theme" TargetControlID="txtstart" Format="dd/MM/yyyy" runat="server">
                                                    </asp:CalendarExtender>

<td align="left">
                                                    <asp:TextBox ID="txtend" runat="server" OnTextChanged="txtend_TextChanged" MaxLength="10" />
                                                    <asp:CalendarExtender ID="CalendarExtender2" CssClass="Cal_Theme" TargetControlID="txtend" Format="dd/MM/yyyy" runat="server">
                                                    </asp:CalendarExtender>
                                                </td>

 <td>
                                                    <asp:CompareValidator ID="CompareValidatorT1" runat="server" ControlToValidate="txtend"
                                                        ControlToCompare="txtstart" Type="Date" ValidationGroup="Page" Operator="GreaterThanEqual"
                                                        ErrorMessage="Invalid Date Range"></asp:CompareValidator>

                                                </td>
Posted
Updated 5-Jun-17 1:41am
Comments
Richard Deeming 6-Jun-17 9:46am    
Why are the dates in different formats? Both of the calendar extenders have the same format set, and it would only confuse your users to have two different controls expecting two different date formats on the same page.

Are you storing the values in the database as strings? If so, you should fix that urgently to use a more appropriate type[^]. The longer you leave it, the more difficult it will be to correct the problem.

1 solution

You will have to convert them to DateTime objects and compare that way.
 
Share this answer
 
Comments
Maciej Los 5-Jun-17 11:44am    
Short and to the point!
5ed!
Member 12605293 6-Jun-17 10:03am    
Hi Maciej,
Answer is precious for me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900