Categories

Archives

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.

The First IT Professional

http://www.youtube.com/watch?v=OMa3QBqf3t4

DateTime data in a C# 2005 Masked Text Box

I had some problems getting DateTime information to display correctly in a Masked TextBox. Each time I assigned DateTime.ToShortDateString to the masked text box it would drop the leading zeros. For example the date 02/04/2007 would show up in the masked text box as 24/20/07 . The format of the ToShortDateString’s output was all wrong for what I needed. After some playing around with it this is the solution that I came up with after reading and playing with the program.

DateTimeFormatInfo myDTFI = new CultureInfo( “en-US”, false ).DateTimeFormat;
myDTFI.ShortDatePattern = “MMddyyyy”;
txtFutureDate.Text = DateTime.Now.ToString(myDTFI.ShortDatePattern);

Silly Me:
Much easier to use the following code. It is much more simplified.

txtFutureDate.Text = String.Format(“{0:MMddyyyy}”, DateTime.Now);