SQL 时间的对比

wuhongyao3 2009-11-19 08:11:47
有这样一个需求,查询当天的数据

表里边有个time字段,这样改怎么查啊?

select * from table where time>当天0点 and time <当天24点

网上也查了下

select * from table where time BETWEEN 当天0点 and 当天24点

但是具体怎么做就不知道了

那位帮忙说下,谢谢。
...全文
74 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
Rotel-刘志东 2009-11-19
  • 打赏
  • 举报
回复
select * from tb where datediff(dd,time,getdate()) = 0
wuhongyao3 2009-11-19
  • 打赏
  • 举报
回复
可以了,谢谢老大们,结贴了。。
kasin000 2009-11-19
  • 打赏
  • 举报
回复
学习
wuhongyao3 2009-11-19
  • 打赏
  • 举报
回复
呵呵,谢谢几位老大,我试试去,马上结贴。。
feixianxxx 2009-11-19
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 icelovey 的回复:]
引用 6 楼 feixianxxx 的回复:
引用 4 楼 dawugui 的回复:
引用 1 楼 feixianxxx 的回复:
select * from table
where datediff(day,[time],getdate())


select * from table
where datediff(day,[time],getdate()) = 0

sorry

多谢乌龟指出.

我看半天, 我说怎么就没个=号呢, 感觉怪怪的

[/Quote]
呵呵 犯迷糊了
kasin000 2009-11-19
  • 打赏
  • 举报
回复

select * from
table
where
datediff(minute,[time],cast((Convert(varchar(10),getdate(),120)+' 00:00:00')as datetime))<=0
ANd
datediff(minute,[time],cast((Convert(varchar(10),getdate(),120)+' 23:59:59')as datetime))>=0
icelovey 2009-11-19
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 feixianxxx 的回复:]
引用 4 楼 dawugui 的回复:
引用 1 楼 feixianxxx 的回复:
select * from table
where datediff(day,[time],getdate())


select * from table
where datediff(day,[time],getdate()) = 0

sorry

多谢乌龟指出.

我看半天, 我说怎么就没个=号呢, 感觉怪怪的
[/Quote]
feixianxxx 2009-11-19
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 dawugui 的回复:]
引用 1 楼 feixianxxx 的回复:
select * from table
where datediff(day,[time],getdate())


select * from table
where datediff(day,[time],getdate()) = 0
[/Quote]
sorry

多谢乌龟指出.
--小F-- 2009-11-19
  • 打赏
  • 举报
回复
select * from table where datediff(dd,time,getdate()) = 0
dawugui 2009-11-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 feixianxxx 的回复:]
select * from table
where datediff(day,[time],getdate())
[/Quote]

select * from table
where datediff(day,[time],getdate()) = 0
feixianxxx 2009-11-19
  • 打赏
  • 举报
回复
select * from table 
where datediff(day,[time],getdate())
dawugui 2009-11-19
  • 打赏
  • 举报
回复
select * from table where datediff(dd , time , getdate()) = 0

select * from table where convert(varchar(10),time,120) = convert(varchar(10),getdate(),120)
feixianxxx 2009-11-19
  • 打赏
  • 举报
回复
select * from table
where datediff(day,[time],getdate())

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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