一起添加时间 [英] Adding times together

查看:83
本文介绍了一起添加时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我的数据库中有一个名为EventDate的字段作为DateTime字段,

因此它同时包含日期和时间这个:

''2004-10-14 08:42:57.000''。


我需要在本专栏中一直加在一起特别是

日期范围(BETWEEN)。


任何建议都会很棒。


谢谢

Sunny :)

Hi guys,

I have a field in my DB called EventDate as a DateTime field,
therefore it holds both the date and time together like this:
''2004-10-14 08:42:57.000''.

I need to add together all the times in this column for a particular
date range (BETWEEN).

Any suggestions will be great.

Thanks
Sunny:)

推荐答案

Sunny K(su*******@yahoo.com)写道:
Sunny K (su*******@yahoo.com) writes:
我的数据库中有一个名为EventDate的字段作为DateTime字段,因此它同时保存日期和时间:
''2004-10-14 08:42:57.000 ''。

我需要在这一栏中一直添加一个特定的日期范围(BETWEEN)。
I have a field in my DB called EventDate as a DateTime field,
therefore it holds both the date and time together like this:
''2004-10-14 08:42:57.000''.

I need to add together all the times in this column for a particular
date range (BETWEEN).




如果我接受了这个词,听起来就像答案是:


SELECT SUM(datefiff(ss,convert(char(8),EventDate,112),E ventDate)

FROM tbl

WHERE EventDate BETWEEN ...和......


但它看起来有点滑稽。


这类查询的一个常见建议是你为你的表发布


o CREATE TABLE语句。

o包含样本数据的INSERT语句。

o给定样本数据所需的结果。


这样可以轻松地剪切和粘贴并组成经过测试的解决方案。 br />

-

Erland Sommarskog,SQL Server MVP, es *** *@sommarskog.se


SQL Server SP3的联机书籍
http://www.microsoft.com/sql/techinf...2000/books.asp


你当然可以将BETWEEN与DATETIME数据类型一起使用,但如果你是
用午夜以外的时间查询值,通常会更方便

使用> =和<而不是BETWEEN。例如


这个:


SELECT *

来自YourTable

WHERE eventdate > =''20041014''

AND eventdate< ''20041015''


相当于:


SELECT *

来自YourTable

WHERE eventdate

BETWEEN''2004-10-14T00:00:00.000''

AND''2004-10-14T23:59:59.997''


希望能回答你的问题。


-

David Portas

SQL Server MVP

-
You certainly can use BETWEEN with the DATETIME datatype but if you are
querying values with times other than midnight it''s often more convenient to
use use >= and < instead of BETWEEN. For example

This:

SELECT *
FROM YourTable
WHERE eventdate >= ''20041014''
AND eventdate < ''20041015''

Is equivalent to this:

SELECT *
FROM YourTable
WHERE eventdate
BETWEEN ''2004-10-14T00:00:00.000''
AND ''2004-10-14T23:59:59.997''

Hope that answers your question.

--
David Portas
SQL Server MVP
--


>我需要在这一栏中一直加在一起


我在第一篇文章中遗漏了这一点 - 也许是因为我不知道它是什么

手段!你期望的结果是什么,例如

''2004-10-14 08:42:57.000''+''2004-12-31 00:00:00.000'' ?你能解释一下

你想要加上DATETIME吗?


-

David Portas

SQL Server MVP

-
> I need to add together all the times in this column

I missed that bit from my first post - maybe because I''ve no idea what it
means! Just what would you expect to be the result of, for example
''2004-10-14 08:42:57.000'' + ''2004-12-31 00:00:00.000''? Could you explain how
you want to add up a DATETIME?

--
David Portas
SQL Server MVP
--


这篇关于一起添加时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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