Click here to Skip to main content
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)



Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 23 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid