27,579
社区成员
发帖
与我相关
我的任务
分享
create table #A1
( id int identity(1,1),
title nvarchar(10) default('title'),
[content] nvarchar(10) default('content'),
userid nvarchar(10) default('userid'),
postdate datetime)
insert #A1(postdate)
select '2011-05-04' union all
select '2011-02-04' union all
select '2011-05-04' union all
select '2011-05-01' union all
select '2011-04-04'
select * from #A1 where datediff(day,postdate,getdate())=1
select cast(CONVERT(varchar(10),GETDATE(),120) as datetime)--当天0时
select DATEADD(SECOND,-1,cast(CONVERT(varchar(10),GETDATE()+1,120) as datetime))--当天23时59分59秒
select * from table_name
where postdate
BETWEEN CONVERT(CHAR(10), DATEADD(DAY, -1, GETDATE()), 120)
AND DATEADD(millisecond, -3, CONVERT(CHAR(10), GETDATE(), 120))
select * from table
where datediff(dd,postdate,getdate())=1
select
*
from
tb
where
postdate>= convert(varchar(10),dateadd(dd,-1,GETDATE()),120)+' 00:00:00'
and
postdate<=convert(varchar(10),dateadd(dd,-1,GETDATE()),120)+' 23:59:59'
select * from table where datediff(dd,postdate,getdate())=1
select * from table
where postdate between convert(varchar(10),dateadd(dd,-1,GETDATE()),120)+' 00:00:00' and
convert(varchar(10),dateadd(dd,-1,GETDATE()),120)+' 23:59:59'
>=cast(dateadd(dd,-1,GETDATE()) as date)
<cast(dateadd(dd,1,GETDATE()) as date)