timestamp database variable is making me troubles when reading a result set

gal mor 141 Reputation points
2022-12-19T08:49:45.26+00:00

hello.
Im trying to get a result set from a select query and loop each row using :

 using (OracleDataReader reader = cmd.ExecuteReader())  
                    {  
                        //for every row  
                        while (reader.Read())  
                        {  
}  

Im getting the data I need exactly the way I need, like:

        item.Order_Company_Id = OracleReaderExtensions.SafeGetString(reader, 7);  
                            item.Order_Btl_Id = OracleReaderExtensions.SafeGetString(reader, 18);  
                            item.Zehut = OracleReaderExtensions.SafeGetString(reader, 9);  
                            item.Time_Stamp = OracleReaderExtensions.SafeGetString(reader, 8);  
                            item.Interface = reader.GetInt32(5).ToString();  

I've been asked to split the data into different CSVs based on a column's value, also.. I did it no problems.
My problem is that "item.Time_Stamp" which is a time_stamp database variable.
I want to read the data in a specific format ( "yyyyMM" ) so ive been trying to do many different conversions and casting, the thing is, that

                            //DateTime dateTime = DateTime.ParseExact(item.Time_Stamp, "(currentformat)", CultureInfo.InvariantCulture);  
  

but the thing is that the timestamp has different values each row ( not every row has the same format which makes it harder for me to solve it.
it looks like:
271959-time.png

would appreciate any help thanks!

SQL Server Other
Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.5K Reputation points
    2022-12-19T10:40:06.2+00:00

    Check a method:

    string example = "10-JAN-22 11:47:55.579000 AM";  
    //string example = "2022-12-01T14:22:01.001";  
      
    DateTime dateTime = DateTime.ParseExact( example,  
        new[] { "dd'-'MMM'-'yy hh':'mm':'ss'.'ffffff tt", "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff" },  
        CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces );  
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.