问题标签 [datetime2]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
23523 浏览

sql-server - 如何计算两个 datetime2 列(SQL Server)之间的间隔?

您好我正在尝试计算两列 datetime2 类型之间的差异。

但是 SQL server (2012) 似乎不喜欢以下内容:

现在,如果我将它转换为日期时间类型,它就可以工作:

但是,当我将它转换为 datetime 时,我失去了精度(注意上面的 3 位小数精度)。在这种情况下,我实际上需要所有 5 个小数点。有没有办法获得两个 datetime2 列之间的间隔并且仍然保持 5 个小数点的精度?谢谢。

0 投票
1 回答
65 浏览

sql - Adding a Primary Key and Altering a Column to DatetTime2

I have a table that tracks statuses that a particular file goes through as it is checked over by our system. It looks like this:
FileID int
Status tinyint
TouchedBy varchar(50)
TouchedWhen datetime

There is currently NO primary key on this table however there is a clustered index on Status and TouchedWhen

As the table has continued to grow and performance decrease in querying against it, one thought I've had is to do add a PrimaryKey so that I get off the heap lookups -- a primary key on FileID, Status and TouchedWhen

The problem I'm running into si that TouchedWhen, due to it's rounding issues, has, on occasion, 2 entries with the exact same datetime.

So then I started researching what it takes to convert that to a datetime2(7) and alter those that are duplicate at that time. My table would then look like:
FileID int
Status tinyint
TouchedBy varchar(50)
TouchedWhen datetime2(7)

And a primarykey on FileID, Status and TouchedWhen

My question is this -- what is the best way to go through and add a millisecond to the existing tables if there are duplicates? How can I do this to a table that needs to remain online?

In advance, thanks,
Brent

0 投票
2 回答
142 浏览

c# - 需要从表值对中以 dd/MM/yyyy 格式输出

这是我将表值对传递给存储过程的代码。DOJ 字段是 DateTime,在 SP 中,DOJ 字段是日期。两者都兼容。输出类似于 dd/MM/yyyy。

如果 DOJ 字段是 DateTime 并且在 SP 中,DOJ 字段是 DateTime2(3),o/p 是 dd/MM/yyyy hh:mm:ss 但我需要 o/p 是 dd/MM/yyyy。我应该如何编写代码?

这是我的存储过程代码 -

0 投票
2 回答
4150 浏览

sql - Datetime2 格式为 dd/mm/yyyy

我在 SQL Server 2008 数据库中有一个数据类型为 datetime2 的列。这意味着我的日期以 YYYY-MM-DDThh:mm:ss 格式显示。但是,我需要我的日期默认采用 dd/mm/YYYY 格式,并且我无法更改列数据类型。此外,datetime2 格式不受 SET LANGUAGE 和 SET DATEFORMAT 会话区域设置的影响。最后,我不想使用 convert() 功能,否则我需要重写所有查询。

如何仍然可以实现?

非常感谢!

0 投票
0 回答
103 浏览

c# - LINQ2SQL 与 DateTime2 的怪异

我的应用程序相当频繁地将消息记录到数据库,因此该表使用 DateTime2 类型以获得更高的精度。

我使用 LINQ2SQL 插入条目,.dbml 上的“服务器数据类型”属性设置为“DATETIME2 NOT NULL”。尽管如此,精度并不总是能达到 DB 层。

我正在插入表单的条目:

在 DB 中,大多数 LogTime 条目正确到毫秒级别,但随后以“0026”结尾。

知道这里发生了什么吗?有没有我错过的技巧?我应该指出,插入这些条目的同一段代码偶尔会以正确的精度成功插入条目......只是不一致。

0 投票
1 回答
1404 浏览

sql - 在 datetime2 中更新时间戳

我们有一个设计为在 MS SQL 2005 上运行的软件,我们已将数据库升级到 2008 R2,并试图通过使用 Datetime2 而不是 Datetime 来提高时间戳的准确性。运行的软件仍然没有变化,并且将具有日期时间的准确性。但是有一个额外的字段用正确的 ms 更新。

所以我的问题是;对于采用 datetime2 并用正确值替换 MS 部分的触发器是否有任何最佳实践?我希望避免对杯子要求很高的转换为字符串并再次返回,但一直无法找到一个好的函数。

0 投票
1 回答
1673 浏览

sql - SQL Server datetime2 和 ODBC

根据MSDN 文档 datetime2的范围从0001-01-019999-12-31。它还说 ODBC 字符串文字如下所示:

为什么最后三个语句失败?仅当值大于1753-01-01并且未使用 ODBC 语法时,它们才会成功。

0 投票
1 回答
210 浏览

sql - 我的 datetime2 比较在字符串起作用的地方不起作用

对于以下语句,我得到了想要的结果。

为什么我运行时没有返回结果?

0 投票
1 回答
274 浏览

datetime - DTS 无法将 datetime2 转换为 datetime

我需要制作一个 DTS 包来将数据从一个数据库转换到另一个数据库。除了所有 datetime2 字段都已更改为 datetime 之外,这些结构基本相同。尝试对数据库运行 DTS 包时,每次遇到无法在不截断的情况下进行转换的 datetime2 字段时都会失败。我真的不在乎精度,我只需要精确到秒的日期和时间。如果我将 DTS 设置为在截断时忽略而不是失败,它会忽略整行并且我最终没有数据。我如何告诉 DTS 这种截断是可以的?

0 投票
0 回答
223 浏览

c# - C# DateTime.Now 数据库中的不同结果

我有一个不同日期的 SQL Server 2008 表:OrderDateDeliveryDate. 我正在使用实体框架 6。

两个字段都是datetime2(0)类型。

这是我在将对象保存到数据库之前创建对象的方式:

当我将它保存到数据库时,日期是不同的,例如:

  • OrderDate 退货2014-08-14 01:52:33
  • DeliveryDate 返回2014-08-14 01:52:31

已经尝试将 datetime2 精度从 0 更改为 7,但没有成功。

请问有什么想法吗?