How to format a date from Oracle to a valid datetime in C #

How do I format a date from Oracle to valid DateTime

in C #?

So ... the oracle format string is a little different from the C # format string DateTime

, so I cannot use that formatted string as an argument to parse. I'm using Devart / CoreLab, but their OracleDate

.Parse seems really strange and doesn't work for me. How can I parse it correctly? Should I call the query in the db with TO_DATE/TO_CHAR

to get the transformation? Or that I should map each oracle format string element to a c # format string element?

edit: And the Oracle and C # format string is different, like MON instead of MMM ...

edit2: more clarification: basically I would have strings that are oracle-date-in-string for example. "08-OCT-85" and I can also get the oracle format pattern following the date string like "DD-MON-YY", "DD-MON-RR", "YYYY / RM / DD" "... etc.

I would like to be able to parse them correctly in C # DateTime

so that I can set them to a Parameter (which C # expects DateTime

) and the problem is that this oracle-date-format pattern is not similar to the C # DateTime-parse- pattern format-pattern.

I suspect there might be some function out there somewhere that might do something like

DateTime dt = ParseDatestringWithSpecifiedOracleDatePatternIntoCSharpDateTime("08-OCT-85", "DD-MON-YY); 

      

right? But I still can't find it :(

+1


source to share


1 answer


Try:



DateTime.ParseExact("08-OCT-85", "dd-MMM-yy", System.Globalization.CultureInfo.InvariantCulture)

      

+1


source







All Articles