Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
i am a student to this programming world
I am doing a csharp project but the problem here i am facing is mask textbox filling with current date. and another mask textbox with current time
like
25/12/2012 and
wit
10:10 AM
i have made this but some error is coming.
maskedTextBox1.Text = DateTime.Now.ToString();

Quote:
but it is filling like this
12/62/012_
how to make this as
06/12/2012
Posted
Updated 7-Apr-20 6:57am
v2
Comments
[no name] 6-Dec-12 7:39am    
Whats your problem ???
shaikh-adil 6-Dec-12 8:18am    
problem?
how can i fill the mask textbox with current date with this format
25/12/2012
ridoy 6-Dec-12 7:53am    
which error?you need to mention that..
shaikh-adil 6-Dec-12 8:16am    
its of bool conversion. but can you suggest answer how to fill masked textbox with 25/12/2012 this type of date
ZurdoDev 6-Dec-12 8:15am    
What's the error?

Try this:

C#
maskedTextBox1.Text = string.Format("{0:dd/MM/yyyy}", DateTime.Now);
 
Share this answer
 
maskedTextBox1.Text = Convert.ToDateTime(DateTime.Now).ToString();
 
Share this answer
 
Comments
shaikh-adil 6-Dec-12 9:40am    
by your code
this is the output 12/62/012_
how to make this as
06/12/2012
CHill60 6-Dec-12 9:51am    
Works fine for me - What is the Mask property on your text box set to?
shaikh-adil 6-Dec-12 10:01am    
the mask propoerty is set to short date
i.e
00/00/0000
shaikh-adil 6-Dec-12 10:05am    
sir can you comment and solve my problem
i have a discussion here in comment. just take a look of comment in this page please
http://www.codeproject.com/Questions/503496/showingplusimageplusonplustab
CHill60 6-Dec-12 10:38am    
You could try maskedTextBox1.Culture = new CultureInfo("en-GB"); prior to putting the data into the maskedtextbox (you will need to use System.Globalization namespace).

Silly question from me ... does it absolutely have to be a *masked* text box - could you just use an ordinary text box and format the date e.g. textBox1.Text = DateTime.Now.ToString("dd/MM/yyyy");
in the form right click properties

custom format yyyy/MM/dd
 
Share this answer
 
This is the best solution i ever found
dtpFrom.Text = System.DateTime.Now.ToShortDateString();
 
Share this answer
 
v2

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