Search code examples
c#asp.netregexoracleodp.net

Unable to parse Oracle timestamp in C#


I have timestamp of Oracle:

string timestamp = "23-JUN-14 09.39.04.000000000 AM";

I am not able to parse it into system date time object. I used:

CultureInfo provider = CultureInfo.InvariantCulture;
                String format = "yy-MMM-dd hh:mm:ss:fffffff";
                string timestamp = "10-DEC-07 10.32.47.797201123 AM";
                {
                    var date = DateTime.ParseExact(timestamp, format, provider);
                    DateTime dateTime = DateTime.ParseExact(timestamp.ToString(), "dd-MMM-y HH:mm:ss", CultureInfo.InvariantCulture);
}

It is still passing error. It is working 7 f after m but not more than that. I used try Parse, try ParseExact - is there any way?


Solution

  • According to https://stackoverflow.com/a/23198962/328864, there is no way to skip parts of an exact pattern, so i guess you could do something like this:

    CultureInfo provider = CultureInfo.InvariantCulture;
    string timestamp = "10-DEC-07 10.32.47.797201123 AM";
    String format = String.Format("yy-MMM-dd hh.mm.ss.fffffff{0} tt", timestamp.Substring(26,2));
    
    DateTime date = DateTime.ParseExact(timestamp, format, provider);
    Console.WriteLine(date);
    

    Not very pretty though.