views:

542

answers:

2

How to parse a string of date in an arbitrary specified Oracle date format in C#?

So... the oracle format string is a bit different from the C# datetime format string, so I can't use that format-string as an argument for the parse. I am using Devart/CoreLab but their OracleDate.Parse seems to be really strange and not working for me. How can I parse it correctly? Do I have to call a query to the db with a TO_DATE/TO_CHAR just to get a conversion? Or that I have to map each oracle format string element into a C# format string element?

edit: And the format string of Oracle and C# are different, such as MON instead of MMM...

edit2: more clarification: Basically I would have strings that are oracle-date-in-string, e.g. "08-OCT-85", and I am also able to get the oracle format pattern that these date string is following, such as "DD-MON-YY", "DD-MON-RR", "YYYY/RM/DD"... etc

I would like to be able to parse them into a C# DateTime properly so that I can set them to Parameter (which expects C# DateTime), and the problem is these oracle-date-format-pattern is not the same as the C# DateTime-parse-format-pattern.

I suspect somewhere out there might exist some function that can do something like DateTime dt = ParseDatestringWithSpecifiedOracleDatePatternIntoCSharpDateTime("08-OCT-85", "DD-MON-YY); right? But I can't find it yet :(

+1  A: 

Could you use DateTime.TryParseExact() with a given format string?

Mitch Wheat
But the format string is the format string of Oracle not C#, such as MON instead of MMM...
Led
+2  A: 

DateTime.TryParseExact allows you do pass a format string to exactly define the format (or an array of formats to try in turn).

Richard
That's what I meant to say, so voted yours up!
Mitch Wheat
But the format string is the format string of Oracle not C#, such as MON instead of MMM...
Led
You need to translate the format string from Oracle formatting syntax to .NET. With the Oracle and .NET references that should be easy (and, if required, should be possible to automate).
Richard