一起添加时间

编程入门 行业动态 更新时间:2024-10-11 05:20:59
本文介绍了一起添加时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 我的数据库中有一个名为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)写道: Sunny K (su*******@yahoo) 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的联机书籍 www.microsoft/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 --

更多推荐

一起添加时间

本文发布于:2023-11-22 00:24:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1615261.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:添加时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!