Fry*_*Fry 19 datetime sql-server-2005
我正在尝试查询特定的时间范围:
我已经看到你可以获得特定范围的数据,但仅限于开始结束,这是更具体的.我没有看到任何直接帮助我的SQL Server命令,所以其他人对你如何形成这个有任何想法吗?
我已经看过了,但我认为这个范围几乎不够具体.
谢谢!
Gig*_*ggy 29
我假设你想要所有这三个作为选择标准的一部分.您需要在您的位置使用一些语句,但它们与您的问题所包含的链接类似.
SELECT *
FROM MyTable
WHERE [dateColumn] > '3/1/2009' AND [dateColumn] <= DATEADD(day,1,'3/31/2009')
--make it inclusive for a datetime type
AND DATEPART(hh,[dateColumn]) >= 6 AND DATEPART(hh,[dateColumn]) <= 22
-- gets the hour of the day from the datetime
AND DATEPART(dw,[dateColumn]) >= 3 AND DATEPART(dw,[dateColumn]) <= 5
-- gets the day of the week from the datetime
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.
你可以试试这个(我今天没有sql server,所以我无法验证语法,抱歉)
select attributeName
from tableName
where CONVERT(varchar,attributeName,101) BETWEEN '03/01/2009' AND '03/31/2009'
and CONVERT(varchar, attributeName,108) BETWEEN '06:00:00' AND '22:00:00'
and DATEPART(day,attributeName) BETWEEN 2 AND 4
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
126294 次 |
| 最近记录: |