在SQL Server 2005数据库中存储一个C#的DateTimeOffset值 [英] Storing a c# DateTimeOffset value in a SQL Server 2005 database

查看:335
本文介绍了在SQL Server 2005数据库中存储一个C#的DateTimeOffset值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要存储在SQL Server 2005数据库AAC#的DateTimeOffset值。



SQL 2008有这个作为一个内置式,但SQL Server 2005中并非如此。



的DateTimeOffset结构具有DateTime值至极我存储为日期时间,一个一个Offset属性(类型为时间跨度)。因为这是相对于UTC的时差,想必是usally在数小时或半小时的整数。如何以最佳方式这个存储在SQL Server 2005数据库?


解决方案


建议>

这不是一个好主意,假设一个偏移数个小时或半小时 - 当然也有一刻钟时区围绕



使用毫秒对于偏移可能是最灵活的,但我认为分钟是一个更容易阅读。如果你曾经去看看原始数据库中的数据,这是容易理解的价值60 = 1一刻比3600000我不能想象你真的需要几分钟的偏移量。

$的分数b $ b

I want to store a a c# DateTimeOffset value in a SQL Server 2005 database.

Sql 2008 has this as a built-in-type, but SQL Server 2005 does not.

The DateTimeOffset structure has a DateTime value wich I store as DateTime, an an Offset property (of type TimeSpan). Since this is the time zone relative to UTC, presumably it is usally at a whole number of hours or half-hours.

Suggestions on how best to store this in a SQL Server 2005 database?

解决方案

It's not a good idea to assume that an offset is a number of hours or half-hours - there are certainly quarter-hour timezones around.

Using milliseconds for the offset is probably the most flexible, but I'd argue that minutes is a lot easier to read. If you're ever going to look at the "raw" data in the database, it's easier to understand value 60 = 1 hour than 3600000. I can't imagine you really needing fractions of minutes as the offset.

这篇关于在SQL Server 2005数据库中存储一个C#的DateTimeOffset值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆