Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MaskedTextBox messes up my short date

2,369 views
Skip to first unread message

Willie Li

unread,
Jun 10, 2008, 6:13:01 PM6/10/08
to
I am using MaskedTextBox with mask "00/00/0000" to display short dates. If a
date is 6/6/2008, the MaskedTextBox would display 66/20/08. If the date
input is 06/06/2008, then the display of the text box is correct.

Is there a simple way to get around this problem?

Thanks.

Willie

VadimKa

unread,
Aug 6, 2008, 11:49:01 PM8/6/08
to
Problem: If I bind a DateTime field to a masked text box with the default
short date mask, the value fails to recognize a leading 0 and shifts all
other digits one place to the left.

Solution: Select the MaskedTextBox. Expand Databindings in Properties.
Click on the ellipses for “(Advanced)”

A dialog box appears where you can set a custom format. Choose custom and
select MM/dd/yyyy as the custom format.


Willie Li

unread,
Aug 8, 2008, 4:46:01 PM8/8/08
to
The problem is that I can't set the binding in the properties, since I am
using LINQ and everything is done at run-time. I wrote a simple function to
convert the format to get around the problem, though.

I do think this is a bug in VS.

husainac

unread,
Oct 31, 2008, 4:23:00 PM10/31/08
to
Willie, I am stuck with the same problem.

Has anyone found a solution to the date display problem of MaskedTextBox
(without databinding) ?

husainac

unread,
Oct 31, 2008, 4:40:03 PM10/31/08
to
I found the solution in the following line of code (VB.net)

Convert.ToDateTime(DataRow.Item("Date")).ToString("MM/dd/yyyy")

ionut

unread,
Dec 9, 2008, 5:58:03 AM12/9/08
to

"husainac" <husa...@discussions.microsoft.com> escribió en el mensaje de
noticias news:E3DD2DCF-E1B3-448A...@microsoft.com...

AndyW

unread,
Jan 7, 2009, 6:01:25 PM1/7/09
to

For C# I wrote a simple method / function that takes a date and returns a
string in the format of mm/dd/yyyy .

public string formatDateAsMMDDYYYY(DateTime d)
{
string result = "";
result = d.Month.ToString().Trim().PadLeft(2, '0');
result += d.Day.ToString().Trim().PadLeft(2, '0');
result += d.Year.ToString().Trim();

return result;

multi...@gmail.com

unread,
Aug 2, 2014, 4:07:07 PM8/2/14
to
Perfect, thanks VadimKa, that is exactly what I needed.

abhisheks...@gmail.com

unread,
Sep 24, 2014, 12:04:51 PM9/24/14
to
Did you get a solution to this???
0 new messages