I want to format the date like this Wed, 04/28/2013.Anyone knows a simple code to format the date like this?
Asked
Active
Viewed 351 times
0
-
Change it to that format, or change it from that format? – Paddyd Jul 09 '13 at 08:35
-
1This question is repeated http://stackoverflow.com/search?q=format+date+c%23 – sameh.q Jul 09 '13 at 08:35
3 Answers
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);

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
-
-
@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