SQL Server中的日期格式 [英] Date format in SQL Server

查看:164
本文介绍了SQL Server中的日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

短问题:

SQL Server中使用的最佳日期格式是什么?

What's the best date format to use in SQL Server?

长说明:

我们将数据库从mysql转换为SQL Server。在mysql中,我们总是使用 int(11)来避免夏令时问题,如果我们在mysql中做同样的事情(或者是 DATETIME 足够好)?

We're converting our database from mysql to SQL Server. In mysql we always used int(11) to avoid the daylight savings time issue, should we be doing the same in mysql (or is DATETIME good enough)?

使用日期有所不同。大多数时候,他们只是提供各种事情发生的信息(为了记录目的)。有时候,他们习惯于要完成工作。

The use of the dates vary. Most of the time they're just informative about when various things occurred (for logging purposes). Sometimes they are used to order work to be done.

我们使用了2005(叹息),但我也很乐意听到关于2008年。

We're using 2005 (sigh), but I'd love to hear about 2008 as well.

推荐答案

我一直使用DATETIME在MSSQL Server中存储时间。它使日期和时间功能变得非常简单 - 我不知道需要编写多少自定义代码才能使用int在日期/时间处理中获得相同级别的功能和速度。为了防止夏令时问题,您可以将日期和时间存储在UTC中而不是服务器时间。而不是使用 DateTime.Now getDate()可以使用 DateTime.UtcNow GETUTCDATE()

I have always used DATETIME to store time in MSSQL Server. It makes date and time functions pretty easy - I'm not sure how much custom code would need to be written to get the same level of functionality and speed in date/time processing using an int. To combat the daylight savings time issue, you can store the date and time in UTC instead of server time. Instead of using DateTime.Now or getDate() you can use DateTime.UtcNow and getutcdate().

这篇关于SQL Server中的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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