tags:

views:

11456

answers:

4

In My Asp.net webpage I need to display today's date into one of the textbox , so in my form load I wrote the following code

textbox1.text = System.DateTime.Today.ToShortDateString();

this line is giving me date like 1/7/09 but I want date like 01/07/09 , Is there anyway I can conver this date into mm/dd/yy format in C#?

+13  A: 
 DateTime.Today.ToString("MM/dd/yy")

Look at the docs for custom date and time format strings for more info.

(Oh, and I hope this app isn't destined for other cultures. That format could really confuse a lot of people... I've never understood the whole month/day/year thing, to be honest. It just seems weird to go "middle/low/high" in terms of scale like that.)

Jon Skeet
I absolutely agree on the wierdness thing, although it's more likely my UK upbringing that makes dd/MM/yy more sensible to me.
ZombieSheep
Well both yy/MM/dd or dd/MM/yy have consistency in their favour - they're either going up or down the significance scale.
Jon Skeet
A: 

Look into using the ToString() method with a specified format.

Kon
+3  A: 

Have you tried the following?:

textbox1.text = System.DateTime.Today.ToString("MM/dd/yy");

Be aware that 2 digit years could be bad in the future...

BenAlabaster
A: 

Check here : http://msdn.microsoft.com/en-us/library/az4se3k1.aspx You can check all the formats and how to implement.

Samiksha