Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
252 views
in Technique[技术] by (71.8m points)

sql - DateTime2与SQL Server中的DateTime(DateTime2 vs DateTime in SQL Server)

Which one:

(哪一个:)

is the recommended way to store date and time in SQL Server 2008+?

(是在SQL Server 2008+中存储日期和时间推荐方法吗?)

I'm aware of differences in precision (and storage space probably), but ignoring those for now, is there a best practice document on when to use what, or maybe we should just use datetime2 only?

(我知道精度(和存储空间可能)的差异,但暂时忽略这些,是否有关于何时使用什么的最佳实践文档,或者我们应该只使用datetime2 ?)

  ask by Mikeon translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The MSDN documentation for datetime recommends using datetime2 .

(datetime的MSDN文档建议使用datetime2 。)

Here is their recommendation:

(以下是他们的建议:)

Use the time , date , datetime2 and datetimeoffset data types for new work.

(使用timedatedatetime2datetimeoffset数据类型进行新工作。)

These types align with the SQL Standard.

(这些类型与SQL标准一致。)

They are more portable.

(它们更便携。)

time , datetime2 and datetimeoffset provide more seconds precision.

(timedatetime2datetimeoffset提供更多的秒精度。)

datetimeoffset provides time zone support for globally deployed applications.

(datetimeoffset为全局部署的应用程序提供时区支持。)

datetime2 has larger date range, a larger default fractional precision, and optional user-specified precision.

(datetime2具有更大的日期范围,更大的默认小数精度和可选的用户指定精度。)

Also depending on the user-specified precision it may use less storage.

(此外,根据用户指定的精度,它可能使用较少的存储空间。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...