Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

masked textbox

Posted on 2006-06-12
5
Medium Priority
?
451 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 1600 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 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Loops Section Overview
Screencast - Getting to Know the Pipeline

782 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