Click here to Skip to main content
13,409,601 members (31,500 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I want to check the condition if the date is correct format then some stuff else i want to be to show the error message.


string date="2/28/2013 12:00:00 AM";

now i want to check the date has been correct format or not..
If ( date=="mm/dd/yyyy ....")
   // message box to be displayed

can any body help me how to do this....
Posted 7-Feb-13 22:58pm
boogac 8-Feb-13 4:22am
I just tried this simple code

string date = "28/02/2013";
DateTime time = Convert.ToDateTime(date);
MessageBox.Show ( String.Format("{0:dd MM yyyy}", Convert.ToDateTime(date)));

you can compare the date string with appopriate format sytle with String.Format() maybe it helps
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Best practice to check in client side for validation.

You may use this code

<asp:TextBox ID="tbxEventDate" Enabled="true" runat="server" CssClass="datepicker input-xlarge"></asp:TextBox>
        <asp:RequiredFieldValidator runat="server" ControlToValidate="tbxEventDate" ID="rfvDate"

            ValidationGroup="validate" CssClass="text-error" Text="required" SetFocusOnError="true"></asp:RequiredFieldValidator>
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Better to give validation on date entry textbox.
naveensenagasetti 8-Feb-13 4:06am
that's not a textbox i fetch the information from Excel sheet that data i want to be to store it on SQL database before that i want to check the date has to be correct format or not

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.180221.1 | Last Updated 23 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100