0

I have an IBM DB2 database, and I need to get values from one column that is primary key and it is TIMESTAMP. That primary key is in this format: dd.MM.yyyy hh:mm:ss.ffffff

I need to get it with full accuracy. But, when I use Entity framework for getting the data last 3 numbers of are lost.

I get this format: dd.MM.yyyy hh:mm:ss.fff. Is there an easy way to solve this problem and get precise data, like telling Entity framework in some way that I am expecting datatime in this specific format?

nemo_87
  • 4,523
  • 16
  • 56
  • 102
  • Is it stored with the milliseconds in the database? If not, you could store it as a string, and then parse it back to a full format using DateTime.ParseExact(): https://msdn.microsoft.com/en-us/library/w2sa9yss(v=vs.110).aspx – Pedro G. Dias May 18 '16 at 08:56
  • It doesn't make sense to have more than 3 digits for the miliseconds. They can only be from 0-999. – Jakob Olsen May 18 '16 at 08:57
  • @PedroG.Dias Hi Pedro, thanks for answering. In DB2 value is stored in correct format. It is a timestamp, the problem occurs when Entity framework gets it from there. I think that it's the one that cut last 3 numbers... – nemo_87 May 18 '16 at 08:58
  • 1
    Maybe a workaround is to map the datetime field to a string, and then using ParseExact, thus bypassing the DateTime conversion done by EF - might not be a good solution in terms of performance though, maybe someone knows a better way? – Pedro G. Dias May 18 '16 at 09:03
  • 2
    No. The problem is, that the DB2 TIMESTAMP appears to have an accuracy of microseconds, but DateTime can only handle miliseconds. He can not hold the full accuracy of TIMESTAMP in a DateTime no matter how he parses it. – Jakob Olsen May 18 '16 at 09:06
  • Possible duplicate of [Timestamp data from DB2 is not accurate when using EntityFramework](http://stackoverflow.com/questions/37298510/timestamp-data-from-db2-is-not-accurate-when-using-entityframework) – Stavr00 May 18 '16 at 14:09
  • Side note: Dates/times/timestamps have no format. When output _as a string_ it will be formatted at that time. The particular format chosen depends on culture, and potentially session settings. – Clockwork-Muse Aug 19 '16 at 07:08

1 Answers1

0

Get the value as both a DateTime and text, parse the microseconds and add them to the DateTime using code from here:

Is there a high resolution (microsecond, nanosecond) DateTime object available for the CLR?

Community
  • 1
  • 1
J. Allen
  • 602
  • 1
  • 7
  • 24