Solved

masked textbox

Posted on 2006-06-12
5
447 Views
Last Modified: 2012-06-21
I am trying to use the Masked TextBox for date.

In the database data is stored as 1/12/2006 not 01/12/2006

I specified the _ _/_ _/_ _ _ _ for the mask and it works fine for entries with double digits for the month like
12/01/2006.  If I have 1 digit months 1/1/2006 then it stores 11/20/06__  

It shifts everthing to fit the mask.  I changed the mask to _/_ _/_ _ _ _ and it works fine for the single months, but then it gets messed up for the double digit months.

How can I make it stop shifting over?


thanks.
0
Comment
Question by:yanci1179
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 10

Expert Comment

by:dkloeck
ID: 16889519
you cant know if the month will be with one or two digits, so you will have to use the two digits format.

There will be a moment when you use the text inside your masked textbox to know a date. At this moment you can just say that a mont with one digit must be written as 0x (for example 01/01/1980) or you can just show at the text of the masked textbox (which could be like 1 /1 /1980) and make a usefull format like 01/01/1980 out of it.

If I have 1 digit months 1/1/2006 then it stores 11/20/06__  (i tryed to do it with 1 digit and it works fine for me so it must be a problem of your application)
0
 
LVL 10

Expert Comment

by:dkloeck
ID: 16889557
maybe you are passing the string to date without handling the spaces first?
0
 
LVL 10

Expert Comment

by:dkloeck
ID: 16889614
//In the database data is stored as 1/12/2006 not 01/12/2006

Sorry, i din't read this,
yyes you are right, the value is wrong then.

You just have to do aut of dates like 1/2/1981 dates like 01/02/1981

0
 
LVL 10

Assisted Solution

by:dkloeck
dkloeck earned 400 total points
ID: 16889719
i tryed it with this code and it works fine:

string dbDate = "1/2/1982";
string newDate = dbDate;
if (newDate.IndexOf("/") < 2)
    newDate = "0" + newDate;
if (newDate.IndexOf("/", 3) < 5)
    newDate = newDate.Insert(3, "0");
maskedTextBox1.Text = newDate;
0
 
LVL 5

Accepted Solution

by:
t_itanium earned 100 total points
ID: 16891774
when you get the data from the database make a simple check..:

string date="";
string day=dbDate.Day.ToString();
string month=dbDate.Month.ToString();;
string year=dbDate.Year.ToString();;

if (day.Length()==2)
{
     date+=day;
}
else
{
    date+="0"+day;  
}

date+="/";

if (month.Length()==2)
{
     date+=month;
}
else
{
    date+="0"+month;  
}

date+="/";

if (year.Length()==4)
{
     date+=year;
}
else
{
    date+="20"+year;  
}

then assign the value of date to the textbox..



cheers
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question