Sandeep Reddy K. Sandeep Reddy K. - 1 year ago 369
ASP.NET (C#) Question

CONVERT date format from mm-dd-yyyy to dd-mmm-yyyy in c#

I am trying insert form field values to oracle database table. I have a date field which is in "MM-DD-YYYY" format. I need to add that date to oracle table. So i am trying to convert that date format to "DD-MMM-YYYY" format. But i am getting the following error.


var creation_date = DateTime.ParseExact(CreationDateTextBox.Text, "DD-MMM-YYYY",null);

Text box value is: 12-12-2013.(No time)
i am getting error like "String was not recognized as a valid DateTime".

Answer Source

This might help :)

String myString = "12-30-2014"; // get value from text field
DateTime myDateTime = new DateTime();
myDateTime = DateTime.ParseExact(myString, "MM-dd-yyyy",null);
String myString_new = myDateTime.ToString("dd-MM-yyyy"); // add myString_new to oracle
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download