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");
  }

Recommended Answers

All 3 Replies

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

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.

@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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.