我需要编写一个查询,它将获取指定日期范围和时间范围之间的所有行。
例如,我想查询2010年9月16日下午5点到2010年9月21日上午9点的所有行。
关于查询应该如何的任何想法?
提前感谢您的帮助!
答案 0 :(得分:21)
SELECT * FROM TABLE
WHERE DATE BETWEEN '09/16/2010 05:00:00' and '09/21/2010 09:00:00'
答案 1 :(得分:3)
事实上这对我有用
SELECT *
FROM myTable
WHERE CAST(ReadDate AS DATETIME) + ReadTime BETWEEN '2010-09-16 5:00PM' AND '2010-09-21 9:00AM'
答案 2 :(得分:1)
你可以试试这个:
SELECT * FROM MYTABLE WHERE DATE BETWEEN '03/10/2014 06:25:00' and '03/12/2010 6:25:00'
答案 3 :(得分:0)
这个怎么样?
SELECT Value, ReadTime, ReadDate
FROM YOURTABLE
WHERE CAST(ReadDate AS DATETIME) + ReadTime BETWEEN '2010-09-16 17:00:00' AND '2010-09-21 09:00:00'
编辑:根据OP的意愿输出; - )
答案 4 :(得分:0)
请记住,美国的日期格式与英国不同。使用英国格式,它必须是,例如
-- dd/mm/ccyy hh:mm:ss
dbo.no_time(at.date_stamp) between '22/05/2016 00:00:01' and '22/07/2016 23:59:59'
答案 5 :(得分:0)
DATE(readingstamp) BETWEEN' 2016-07-21' 和' 2016-07-31' 和时间(阅读戳) BETWEEN' 08:00:00' AND' 17:59:59'
简单地分开日期和时间的转换
答案 6 :(得分:0)
使用DBName
从TABLE_NAME A中选择*
其中A.date> ='2018-06-26 21:24'和A.date <='2018-06-26 21:28';
答案 7 :(得分:-2)
"SELECT Applicant.applicantId, Applicant.lastName, Applicant.firstName, Applicant.middleName, Applicant.status,Applicant.companyId, Company.name, Applicant.createDate FROM (Applicant INNER JOIN Company ON Applicant.companyId = Company.companyId) WHERE Applicant.createDate between '" +dateTimePicker1.Text.ToString() + "'and '"+dateTimePicker2.Text.ToString() +"'";
这就是我所做的!!