我应该将DateTimes作为一个Long(Ticks)存储在数据库中吗? [英] Should I store DateTimes as a Long (Ticks) in a database?

查看:98
本文介绍了我应该将DateTimes作为一个Long(Ticks)存储在数据库中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过将DateTime值保存为 long 可以使生活变得更容易在使用null DateTime值时,无论存储还是检索 - null DateTimes,无效的DateTimes等都总是令人痛心的,总是出现问题。

Could life be made easier by saving DateTime values as a long instead? There always seem to be problems when working with null DateTime values, whether storing or retrieving - null DateTimes, invalid DateTimes, etc. are always a pain to work with.

建议您使用 long 数据类型,因为您可以随时从刻度线创建DateTime ?

Would it be advisable to simply work with a long data type since you can always create a DateTime from the ticks?

编辑:
我使用SqlServer和MySql。 SqlDateTime是 DateTime 的.net派生。所有3个平台之间有一个有效的日期时间有差异。如何处理这些差异?

I work with SqlServer and MySql. SqlDateTime is a .net derivation of DateTime. There are differences between all 3 platforms of what a valid DateTime is. How do you handle these differences?

推荐答案

我想这是个人喜好。我总是使用datetime类型,并没有任何困扰他们。

I guess that's down to personal preference. I always work with datetime types and don't have any bother with them.

如果你在很长的时间内存储他们不再是日期。如果你想做一个查询来选择在星期五添加的所有帐户(说),你将不得不跳过几个环来工作。

If you store them as longs though semantically they are no longer dates. If you ever wanted to do a query to select all accounts added on a Friday (say) you would have to jump through several hoops to work that out.

这篇关于我应该将DateTimes作为一个Long(Ticks)存储在数据库中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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