SQL 关于指定日期搜索语句得写法
sql = " select * from test where ([name] like '%" & ms & "%') " & _
" and datediff(day,dateandtime, '" & date() & "')=0"
sql="select * from test where (name like '%"& ms &"%') and convert(varchar(10),dateandtime ,120)=convert(varchar(10),getdate(),120)
sql="select * from test where (name like '%"& ms &"%') and (rq like '%"& SUBSTRING(CONVERT(char(4), dateandtime, 21), 0, 11) &"%')"
上面3句都是用来搜索当前日期得相关条件得数据,请问,如果要搜索当前一天得前一天(昨天),改怎么写?
如果要搜索从7天前到当前日期(一周),该怎么写?
WHERE DATEDIFF(DAY, yourDate, GETDATE()) <= 7 --一周之内的
WHERE DATEDIFF(DAY, yourDate, GETDATE()) = 1 --前一天的
留言区(共0条)