Reputation: 3675
How to I format datetime from sql to certain format user defined in C#? For example, the datetime in sql is like 2011-02-06 12:00:21, the user defined format is mmddyyyy, I am expecting output is 02062011 (note that not 262011). How do I do the conversion in C#?
Upvotes: 0
Views: 116
Reputation: 63966
This should do it:
((DateTime)reader["DateColumn"]).ToString("MMddyyyy");
Assuming reader["DateColumn"]
returns a DateTime
object
Upvotes: 1
Reputation: 9139
Be more specific. Consuming you have DateTime object. If you want to show it you can use ToString
overload method:
new DateTime(2011, 2, 6).ToString("MMddyyyy");
Upvotes: 1