abdulmanan
abdulmanan

Reputation: 45

How to Get Desire Time and Date Format in C#?

I want to Get date-time Format like (30 April 1990) my date is store in sql server Database in default Format mm/dd/yyyy. how to do that?

tsddate.Text = orderReader["deliveryDate"] as DateTime = new DateTime(?,,????);

Upvotes: 0

Views: 237

Answers (2)

Sameer
Sameer

Reputation: 2171

tsddate.Text = String.Format("{0:dd MMMM yyyy}",orderReader["deliveryDate"]);

Upvotes: 1

middelpat
middelpat

Reputation: 2585

You can specify custom datetime formats using the ToString overload.

like:

DateTime now = DateTime.Now;
string formatted = now.ToString("dd-MM-yyyy");

And in your situation it would be something like:

DateTime date = DateTime.ParseExact(orderReader["deliveryDate"].ToString(), "MM/dd/yyyy HH:mm:ss", new System.Globalization.CultureInfo("en-US"));
tsddate.Text = date.ToString("dd MMMM yyyy");   

see all the formats you can use here: http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx

Upvotes: 2

Related Questions