Click here to Skip to main content
11,706,799 members (45,053 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0
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.

ex:

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 ....")
   //inserting
else
   // message box to be displayed

can any body help me how to do this....
Posted 7-Feb-13 21:58pm
N@veen.S1.6K
Comments
boogac at 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
good
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>
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Better to give validation on date entry textbox.
  Permalink  
Comments
naveensenagasetti at 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
0 Sergey Alexandrovich Kryukov 140
1 OriginalGriff 125
2 chainerlt 110
3 ppolymorphe 109
4 Mika Wendelius 70
0 OriginalGriff 9,178
1 Sergey Alexandrovich Kryukov 8,487
2 CPallini 5,189
3 Maciej Los 4,766
4 Mika Wendelius 3,696


Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 23 Feb 2013
Copyright © CodeProject, 1999-2015
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