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.
If you already have it as a DateTime , use: string x = dt. ToString("yyyy-MM-dd");
Try this code:
string formattedDate = YourDate.ToString("dd MMM yyyy");
It will format to like:
12 Nov 2012
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"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With