Reputation: 1230
How can I convert 1-2-2016
to Datetime format dd-MMM-yyyy
For Example :
The output of 1-2-2016
should be 1-Feb-2016
I've tried the following code but it's returing 2-Jan-2016
.
Updated_Value = Convert.ToDateTime(Updated_Value).ToString("dd-MMM-yyyy");
The Data in Update_Value
variable is coming from database whose datatype is varchar.
Kindly Help me to resolve this .
Thanks in advance .
Upvotes: 0
Views: 280
Reputation: 5890
Try this:
DateTime dt;
DateTime.TryParseExact(Updated_Value, "d-M-yyyy", System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.None, out dt);
var newdate = dt.ToString("d-MMM-yyyy");
Upvotes: 2