Click here to Skip to main content
15,910,877 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Sir,
I have to show automatic current date in Textbox not time
C#
Text='<%# System.DateTime.Now %>'
doing this showing default time in my textbox please tell how could I show only date in Textbox in C#
Posted
Updated 6-Dec-11 0:55am
v2

Have you tried using Date[^] property, something like
C#
System.DateTime.Now.Date
 
Share this answer
 
textbox1.Text = DateTime.Now.ToShortDateString();
 
Share this answer
 
v2
Comments
Prashant Srivastava LKO 7-Dec-11 3:26am    
but the format is coming wrong it is coming in MM/dd/yyyy instead of dd/MM/yyyy
CSS
DateTime dt=DateTime.Now;

textbox1.Text=DateTime.Now.Today
 
Share this answer
 
Comments
Abhi KA 6-Dec-11 7:11am    
second statement is enough
Try
MSDN-[DateTime.Now Property ][^] which responsible to gets a DateTime object that is set to the current date and time on this computer, expressed as the local time.
 
Share this answer
 
System.DateTime.Now.ToString(); works fine and shows both date and time , But you can use system.DateTime.Now.Date.ToString(); it will surely work for date
 
Share this answer
 
Comments
OriginalGriff 5-Feb-17 3:29am    
While I applaud your urge to help people, it's a good idea to stick to new questions, rather than 6 year old, solved ones.
Answering old questions can be seen as rep-point hunting, which is a form of site abuse. The more trigger happy amongst us will start the process of banning you from the site if you aren't careful. Stick to new questions and you'll be fine.
But ... since this doesn't actually answer the question - it will provide a string containing midnight if the system is set to it - I recommend that you delete it before you get downvoted. It's a very, very good idea to check your answers work in the OP's environment before you post them...

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