Windows Develop Bookmark and Share   
 index > Windows Forms General > Masked TextBox and setting Current date
 

Masked TextBox and setting Current date

Help, I have two Masked TextBoxs I have formatted to use the short date format.

How do I preload both textboxes with todays date?

Also How can I validate the textbox dates assuimg USA date format mm/dd/yyyy?

I've tried the IsDate() function and sometimes 7/32/20 will pass.
Red2003XLT  Thursday, September 17, 2009 7:02 PM
Just set the textbox using:

textBox1.Text = DateTime.Now.ToString("mm/dd/yyyy");

When you go to validate the text, you can use DateTime.ParseExact to verify that it's a valid date:

bool validDate = true;
try {
DateTime date = DateTime.ParseExact(textBox1.Text, "mm/dd/yyyy", CultureInfo.InvariantCulture);
}
catch (FormatException)
{
validDate = false;
}



Reed Copsey, Jr. - http://reedcopsey.com
Reed Copsey, Jr.  Thursday, September 17, 2009 7:18 PM
I just tried textBox1.Text = DateTime.Now.ToString("mm/dd/yyyy");

I get "29/17/2009"

BTW:I'm using Visual Basic 2005 .NET if that helps.
Red2003XLT  Thursday, September 17, 2009 7:31 PM
Oops - sorry, the format should be:

"MM/dd/yyyy"

"mm" is minutes, "MM" is months. See MSDN for details .

Reed Copsey, Jr. - http://reedcopsey.com
Reed Copsey, Jr.  Thursday, September 17, 2009 7:38 PM

You can use google to search for other answers

Custom Search

More Threads

• Edit ArrayList composed of strings in PropertyGrid control
• Menu Shortcuts don´t work with ActiveX controls
• How to use HelpcontextId in HelpProvider
• How can i draw graphics on a different form
• How can I draw the current cursor using GDI+?
• Powershell -- "kill -SIGUSR1 (pid)"?
• app config on network drive
• ToolTip for listviewitem and setting delay
• How can I lock autorun feature with shellexecute option.
• Active Directory