Connecting Tech Pros Worldwide Forums | Help | Site Map

Short date to long date

Mike L
Guest
 
Posts: n/a
#1: Nov 17 '05
After the user enter in short date in text box, once the user tabs out of the
text box I want the short date to change automatically to long date. What is
the code to make this change and what is the best event to put it in?



Brendan Grant
Guest
 
Posts: n/a
#2: Nov 17 '05

re: Short date to long date


There are 3 parts to accomplishing this, all quite easy.

First up, you’ll want to subscribe to the TextBox’s Leave event.

Next, you would need to read the value from the TextBox and convert it into
a DateTime class, easiest way to do that is with the static Parse() method
that is part of the DateTime class.

Finally, output the LongDate format by calling the ToLongDateString() method
on the instance you just created.

All in all, the majority of your code would look not unlike:

private void myTextBox_Leave(object sender, System.EventArgs e)
{
DateTime enteredDate = DateTime.Parse(myTextBox.Text);
textBox1.Text = enteredDate.ToLongDateString();
}

One note, it would be wise to do some sort of checking prior to the Parse(),
or at least wrap it in a try/catch block just incase the user puts in an
invalid date that it chokes on.

Brendan


"Mike L" wrote:
[color=blue]
> After the user enter in short date in text box, once the user tabs out of the
> text box I want the short date to change automatically to long date. What is
> the code to make this change and what is the best event to put it in?[/color]
Jeffrey Tan[MSFT]
Guest
 
Posts: n/a
#3: Nov 17 '05

re: Short date to long date


Hi Cadel,

Does Brendan's reply make sense to you? Is your problem resolved? Please
feel free to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Closed Thread