select title from TA WHERE GuestDatetime >= '" & Trim(Request("keyword")) & "' and GuestDatetime <dateadd(day,1, '" & Trim(Request("keyword")) & "')
select title from TA WHERE GuestDatetime between '" & Trim(Request("keyword")) & " 00:00:00' and '" & Trim(Request("keyword")) & " 23:59:59'
如果数据量不大,用datediff是可以的,否则影响性能就最好用>=和<
谢谢各位 ,继续追问下,如果数据库是ACCESS,语句该怎么写?
access 的时间用 # 标示,不过不知道是否支持 dateadd()函数
declare @t table(id int,GuestDatetime datetime,title varchar(64)) insert into @t select '1','2008-7-26 16:26:30','第一个留言' union all select '2','2008-7-5 13:11:48','第二个留言' union all select '3','2008-7-26 16:26:30','第三个留言'select * from @t where convert(varchar,GuestDatetime,23)='2008-07-26'
access 的时间用 # 标示,不过不知道是否支持 dateadd()函数
insert into @t
select '1','2008-7-26 16:26:30','第一个留言'
union all
select '2','2008-7-5 13:11:48','第二个留言'
union all
select '3','2008-7-26 16:26:30','第三个留言'select * from @t where convert(varchar,GuestDatetime,23)='2008-07-26'