Solved

masked textbox

Posted on 2006-06-12
5
445 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
  • 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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