在 DateTime 字段中的两个日期之间进行选择 - SQL Server

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1945722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 04:50:01  来源:igfitidea点击:

Selecting between two dates within a DateTime field - SQL Server

sqlsql-server-2005datetime

提问by bala3569

How to select records between a date to another date given a DateTime field in a table.

如何在给定表中的 DateTime 字段的情况下选择一个日期到另一个日期之间的记录。

回答by Oded

SELECT * 
FROM tbl 
WHERE myDate BETWEEN #date one# AND #date two#;

回答by Tikeb

select * 
from blah 
where DatetimeField between '22/02/2009 09:00:00.000' and '23/05/2009 10:30:00.000'

Depending on the country setting for the login, the month/day may need to be swapped around.

根据登录的国家/地区设置,可能需要交换月/日。