Getting DateTimeOffset value from SQL 2008 to C #

I have a SQL 2008 table with a RecDate field of type DateTimeOffset.

For this entry, the value is '2010-04-01 17: 19: 23.62 -05: 00'

In C #, I create a DataTable and populate it with the results of "SELECT RecDate FROM MyTable".

I need to get the milliseconds, but if I do the following, the milliseconds are always 0:

DateTimeOffset dto = DateTimeOffset.Parse(dt.Rows[0][0].ToString()); 

What is the correct way to get the value in the RecDate column in the dto variable?

+6
c # sql datetimeoffset sql-server-2008
source share
1 answer

Probably, for broadcasting ToString() information about microseconds is deleted.

According to MSDN , the SQL Server datetimeoffset data type corresponds to C # datetimeoffset . Therefore, you should put the datetimeoffset columns in the datetimeoffset .

For example:

 DateTimeOffset dto = (DateTimeOffset) Rows[0][0]; 
+9
source share

All Articles