SELECT ID,PName,PDate from testtable
where cdate(PDate)>=cdate('2009-7-6 16:00')
and cdate(PDate)<=cdate('2009-7-7 9:00')
---或
SELECT ID,PName,PDate from testtable
where cdate(PDate)>=#2009-7-6 16:00#
and cdate(PDate)<=#2009-7-7 9:00#
--今天09:00至 昨天16:00后
SELECT ID,PName,PDate from testtable
where
(cdate(PDate)>=dateadd('h',-8,date()))
and (cdate(PDate)<=dateadd('h',9,date()))
--或
SELECT ID,PName,PDate from testtable
where (cdate(PDate) between dateadd('h',-8,date()) and dateadd('h',9,date()))
string str1 = this.txtStartDate.Text.ToString();
string str2 = this.txtEndDate.Text.ToString();
int str3 = Convert.ToInt32(this.txtStartTimes.Text.ToString());
int str4 = Convert.ToInt32(this.txtEndTimes.Text.ToString());
string sql=string.format("select * from WorkEffict where (Dates>#{0} {2}:00# and Dates<#{1} {3}:00#) and (hour(Dates)>={2} or hour(Dates)<={3})",str1,str2,str3,str4)
//原理:查询出开始日期当天16:00以后及截止日期后一天9:00之前且时间数大于16或者小于9的所有记录
后面这段是手写的,你检查一下。
精确到秒, 可以参考
string str1 = this.txtStartDate.Text.ToString();
string str2 = this.txtEndDate.Text.ToString();
string str3 = this.txtStartTimes.Text.ToString();//eg,"16:32:23"
string str4 = this.txtEndTimes.Text.ToString(); // eg,"09:00:00"
string sql = string.format("select * from WorkEffict where (Dates>#{0} {2}# and Dates<#{1} {3}#) and (format(Dates, \"hh:mm:ss\") >=#{2}# or format(Dates, \"hh:mm:ss\") <=#{3}#)", str1, str2, str3, str4);
为什么?你怎么写的sql语句
Access中不能用btween and
可以用:
Select * from 表名 where 日期>= #晚上18:00# and 日期 <= #早上9:00#
建议先用字符串处理将”2009-09-10 18:30:00”去掉日期部分where条件用小时比较,写之前考虑一下便捷 18:00:00————24:00:00,0:00:00————9:00:00