开发者

Getting DateTimeOffset value from SQL 2008 to C#

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

For a given re开发者_如何转开发cord the value is '2010-04-01 17:19:23.62 -05:00'

In C# I create a DataTable and fill 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 proper way to get the value in the RecDate column into the DTO variable?


Perhaps the cast to ToString() removes the microsecond info.

According to MSDN, the SQL Server data type datetimeoffset matches C#'s DateTimeOffset. So it should be safe to cast a datetimeoffset column to DateTimeOffset.

For example:

DateTimeOffset dto = (DateTimeOffset) Rows[0][0];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜