How to format a date from Oracle to a valid datetime in c# [duplicate]

梦想与她 提交于 2019-12-24 07:10:14

问题


How to format a date from Oracle to a valid DateTime 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:


Try:

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


来源:https://stackoverflow.com/questions/19848777/how-to-format-a-date-from-oracle-to-a-valid-datetime-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!