john
john

Reputation: 63

Date formatting using c#

Hi I am having an application which uses oracle as backend. what is the correct format while passing the parameters to stored procedure from c sharp? If the format is dd-mmm-yyyy. i.e 30-jan-2011. How to convert a date which is in mm/dd/yyyy (01/30/2011) to dd-mmm-yyyy (30-jan-2011)?

Upvotes: 0

Views: 1488

Answers (5)

Divi
Divi

Reputation: 7701

Its string.format("{0:dd-MMM-yyyy}", date)

Upvotes: 0

Ta01
Ta01

Reputation: 31630

You could use :

dt.ToString("dd-MMM-yyyy")

dt being your DateTime variable

Upvotes: 1

Jeff Fritz
Jeff Fritz

Reputation: 9861

You should load the value into a DateTime type with a parse, and output with a ToString()

var d = DateTime.ParseExact("01/30/2011","mm/dd/yyyy");
string readyForOracle = d.ToString("dd-MMM-yyyy");

ParseExact method docs:

http://msdn.microsoft.com/en-us/library/system.datetime.parseexact.aspx

DateTime custom formatting docs:

http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

Upvotes: 2

James
James

Reputation: 641

String.Format("{0:mm/dd/yyyy}", date);  // 01/30/2011
String.Format("{0:dd-MMM-yyyy}", date);  // 30-jan-2011

Upvotes: 0

kyrylomyr
kyrylomyr

Reputation: 12652

Date formatting described on MSDN.

Will be something like this:

DateTime dt = ...; //Getting your date.
string newFormat = dt.ToString("dd-MMM-yyyy");

Upvotes: 0

Related Questions