Click here to Skip to main content
15,900,815 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a textbox in which i want to give date in a "dd/MMM/YYYY" format. for this i want to check the textbox format in there leave event. so tell me the C# coding to check this condition in textbox leave event.
Posted

Try:
C#
DateTime result;
if (DateTime.TryParseExact(myTextBox.Text, "dd/MMM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out result))
{
    // OK
}
else
{
    // Error!
}
 
Share this answer
 
Hello :
to check you can :
if (DateTime.TryParseExact(TextBox1.Text, "MM/dd/yyyy", null, DateTimeStyles.None, out Test) == true)


else instead of checking you can directly change the string to any format you want :

DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123);

String.Format("{0:y yy yyy yyyy}", dt);  // "8 08 008 2008"   year
String.Format("{0:M MM MMM MMMM}", dt);  // "3 03 Mar March"  month
String.Format("{0:d dd ddd dddd}", dt);  // "9 09 Sun Sunday" day
String.Format("{0:h hh H HH}",     dt);  // "4 04 16 16"      hour 12/24
String.Format("{0:m mm}",          dt);  // "5 05"            minute
String.Format("{0:s ss}",          dt);  // "7 07"            second
String.Format("{0:f ff fff ffff}", dt);  // "1 12 123 1230"   sec.fraction
String.Format("{0:F FF FFF FFFF}", dt);  // "1 12 123 123"    without zeroes
String.Format("{0:t tt}",          dt);  // "P PM"            A.M. or P.M.
String.Format("{0:z zz zzz}",      dt);  // "-6 -06 -06:00"   time zone


regards...
 
Share this answer
 
Comments
tanisha pandey 15-Aug-11 3:32am    
can you please tell me what is the "DateTimeStyles" in your first solution and how can i get this?
Sergey Alexandrovich Kryukov 15-Aug-11 23:30pm    
No change to read the standard MSDN help page?
--SA

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