求零时的日期

cqq 2011-05-04 03:53:12
这样的,
每天都要统计一下昨天的用户发帖排行榜,
表结构大体是这样的

id title content userid postdate


那么这个昨天的时间段怎么的出来?

select * from table where postdate>?? and postdate<???

...全文
133 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
liang145 2011-05-05
  • 打赏
  • 举报
回复

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

凑热闹~~
ly745455 2011-05-04
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 dawugui 的回复:]
引用楼主 cqq 的回复:
这样的,
每天都要统计一下昨天的用户发帖排行榜,
表结构大体是这样的

id title content userid postdate


那么这个昨天的时间段怎么的出来?

select * from table where postdate>?? and postdate<???


select * from table where d……
[/Quote]
++++
gogodiy 2011-05-04
  • 打赏
  • 举报
回复

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秒
Shawn 2011-05-04
  • 打赏
  • 举报
回复
select * from table_name
where postdate
BETWEEN CONVERT(CHAR(10), DATEADD(DAY, -1, GETDATE()), 120)
AND DATEADD(millisecond, -3, CONVERT(CHAR(10), GETDATE(), 120))
Rotel-刘志东 2011-05-04
  • 打赏
  • 举报
回复
select * from table 
where datediff(dd,postdate,getdate())=1
dawugui 2011-05-04
  • 打赏
  • 举报
回复
[Quote=引用楼主 cqq 的回复:]
这样的,
每天都要统计一下昨天的用户发帖排行榜,
表结构大体是这样的

id title content userid postdate


那么这个昨天的时间段怎么的出来?

select * from table where postdate>?? and postdate<???
[/Quote]

select * from table where datediff(dd,postdate,getdate()) = 1
--小F-- 2011-05-04
  • 打赏
  • 举报
回复
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'
Lisliefor 2011-05-04
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ssp2009 的回复:]

SQL code
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'
[/Quote]
楼上完美。
百年树人 2011-05-04
  • 打赏
  • 举报
回复
select * from table where datediff(dd,postdate,getdate())=1
快溜 2011-05-04
  • 打赏
  • 举报
回复
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'
cqq 2011-05-04
  • 打赏
  • 举报
回复
类型 date 不是已定义的系统类型。
gw6328 2011-05-04
  • 打赏
  • 举报
回复

>=cast(dateadd(dd,-1,GETDATE()) as date)
<cast(dateadd(dd,1,GETDATE()) as date)

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧