0

This is a Simple one Line code for inserting current System date in to a text box:

 protected void Page_Load(object sender, EventArgs e)
 {
  TextBox1.Text = DateTime.Now.ToString("dd/MM/yyyy");
  }

Edited by __avd: Improved the formatting.

4
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Mike Askew
0

per heps you can store first your date in a string as :

DateTime dt= datetimenow.now;
string str_dt=String.Format("{0:dd/MM/yyyy}", dt);
textbox1.test=str_dt;

i wish he gonna help you

0

i wish he gonna help you

I don't think he was asking a question...

This is a Simple one Line code for inserting current System date in to a text box:

What is the point of this? Not that I don't understand the code, or its purpose, but why post it? It's pretty trivial.

0

@nmaillet, It was probably intended as a code snippet, even then it is very trivial to most of the forums, the only completely non basic functionality is the date format masking and that doesnt take much.

Of course its worth remembering Console.WriteLine(DateTime.Now.ToShortDateString()); Does exactly the same thing as this, but without the need for typing the mask, which instead automatically changes according to the culture settings of the machine (en-US (M/d/yyyy), de-DE (dd.MM.yyyy) etc etc).

The MSDN for this

Edited by Mike Askew

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.