0

I want to format the date like this Wed, 04/28/2013.Anyone knows a simple code to format the date like this?

Andrii Kalytiiuk
  • 1,501
  • 14
  • 26
user335160
  • 1,364
  • 6
  • 32
  • 67

3 Answers3

5

You have to pass CultureInfo.InvariantCulture to ToString to ensure that / as date separator is used since it would normally be replaced with the current culture's date separator:

string date = dt.ToString("ddd, MM/dd/yyyy", CultureInfo.InvariantCulture);

Demo

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • actually, it should replace the separator if other language was set. Should I take out the CultureInfo.InvariantCulture to apply this behavior? – user335160 Jul 09 '13 at 08:38
  • @user335160: If you want to use the current culture's date separator(e.g. `.` in germany) you just have to remove the second parameter or pass `null`. – Tim Schmelter Jul 09 '13 at 08:42
  • Tim Schmelter-thank you very much. – user335160 Jul 09 '13 at 08:45
  • @user335160: One note: if you want to mix both, e.g. the current culture's day-name but the `/` as date separator you have to concat both: `dt.ToString("ddd") + dt.ToString(", MM/dd/yyyy", CultureInfo.InvariantCulture);` – Tim Schmelter Jul 09 '13 at 08:46
0

Use a string ;) Here's an example for you: http://www.dotnetperls.com/datetime-format

Llama
  • 122
  • 2
  • 2
  • 8
0

insert DatetimePicker

dateTimePicker1.Value.toString("MM/dd/yyyy");

Second option Create DateTime Variable

DateTime da=new DateTime();

and where you want to use call like this

da.DateTime.Now();

Hope You Liked it

slavoo
  • 5,798
  • 64
  • 37
  • 39
user2491383
  • 160
  • 2
  • 4
  • 13