Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Date to "dd-MMM-yyyy" format c#

Tags:

c#-3.0

Guys i am unable to convert datetime to "dd-MMM-yyyy" format. My code is given below:

TreeNode tn = new TreeNode(dr["pBillDate"].ToString());       // Here i am getting both date and time.

I need to convert it as "20-Mar-2013".

Please help me. Thanks.

like image 666
Apurba Avatar asked Mar 21 '13 12:03

Apurba


People also ask

How do I change the date format in C sharp?

If you already have it as a DateTime , use: string x = dt. ToString("yyyy-MM-dd");


2 Answers

Try this code:

string formattedDate = YourDate.ToString("dd MMM yyyy");

It will format to like:

12 Nov 2012
like image 132
Rashad Valliyengal Avatar answered Oct 06 '22 00:10

Rashad Valliyengal


The following couple examples should work:

DateTime dt = Convert.ToDateTime(dr["pBillDate"]);

TreeNode tn = new TreeNode(String.Format("{0:dd-MMM-yyyy}", dt));

or

DateTime dt = Convert.ToDateTime(dr["pBillDate"]);

TreeNode tn = new TreeNode(dt.ToString("dd-MMM-yyyy"));
like image 40
Brandon.Staley Avatar answered Oct 05 '22 23:10

Brandon.Staley