Click here to Skip to main content
14,832,124 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

I am using the visual studio 2010 (C#) to build a form displaying the records from a SQL table. The problem is the masked textbox. The mask I set to is short date 00/00/0000, but it displayed the dates wrong. For example, if the date in the database is "02/03/1990", it displays "23/19/90__".

The other problem I have is, sometimes there is no Date to document, so I need to leave it blank, but it would not allow me to leave the textbox control, if I don't provide it with a date! (The DB column in SQL database is set to "allow null")

Any help would be greatly appreciated!
Posted

It seems as though you should check your system localization settings to get the date in the proper format.
   
Comments
Saeed Jafarian 12-Aug-11 9:28am
   
I checked that before, not help
[no name] 12-Aug-11 10:00am
   
What about the database? How is the value being stored there?
Sorry for the wrong url, I have fixed it now.

There is an example here which uses masked textbox to display date just like you want. See if this helps. Just click the C# tab to view the example. The example is present all the way down in the page.http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox[^]

Another method:
You could also use DateTimePicker control rather than textbox. To display date in a format you want, just click the DateTimePicker control and in its properties, set Format=Short.
   
v3
Comments
Saeed Jafarian 12-Aug-11 9:31am
   
the link says: content not found
and i know DateTimePicker is so much better but in this situation i should use maskedtextbox :((
Praveen Kullu 13-Aug-11 13:34pm
   
Sorry for the wrong link, i have fixed it now.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900