时间查询的小问题。

ntwqy_2008 2009-09-10 09:36:11
数据库中有一时间字段的存储的是‘2009-9-9 15:44:40’年月日时分秒

我想查询表中是否有2009年9月9日的记录,
select count(*) from 表A where Time ='2009-9-9' 结果为0???查询不到啊??

应该怎么写呢??谢谢大家。
...全文
57 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
chengzhenabc 2009-09-10
  • 打赏
  • 举报
回复
本人新手,诚心跪求高手,QQ:654467692。
ntwqy_2008 2009-09-10
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 sql77 的回复:]
引用 10 楼 ntwqy_2008 的回复:
不懂啊。能否讲解下什么意思啊。谢谢。

DATEDIFF()函数是比较差值的,
CONVERT()是转换格式的
[/Quote]

谢谢。
SQL77 2009-09-10
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 ntwqy_2008 的回复:]
不懂啊。能否讲解下什么意思啊。谢谢。
[/Quote]
DATEDIFF()函数是比较差值的,
CONVERT()是转换格式的
ntwqy_2008 2009-09-10
  • 打赏
  • 举报
回复
不懂啊。能否讲解下什么意思啊。谢谢。
lihan6415151528 2009-09-10
  • 打赏
  • 举报
回复

create table test(dtime datetime)
insert test
select '2009-9-9 15:44:40'
go

select count(*) from test where datediff(dd,'2009-9-9',dtime)=0


-----------
1

(所影响的行数为 1 行)


soft_wsx 2009-09-10
  • 打赏
  • 举报
回复
select count(1) FROM 表A where left(time,8)='2009-9-9' 
黄_瓜 2009-09-10
  • 打赏
  • 举报
回复
--1
select count(*) from 表A where convert(varchar(10),Time,120) ='2009-09-09'
--2
select count(*) from 表A where datediff(day,datefield,'2009-9-9')=0
SQL77 2009-09-10
  • 打赏
  • 举报
回复
select count(*) from 表A where CONVERT(VARCHAR(10),Time,120) ='2009-09-09'
黄_瓜 2009-09-10
  • 打赏
  • 举报
回复
select count(1) FROM 表A where  datediff(dd,''2009-9-9' ',[time])=0
xiequan2 2009-09-10
  • 打赏
  • 举报
回复
convert(varchar(10),time,120) 转化一下
水族杰纶 2009-09-10
  • 打赏
  • 举报
回复
select count(*) from 表A where convert(varchar(10),Time,120)  ='2009-09-09' 
csdyyr 2009-09-10
  • 打赏
  • 举报
回复
select count(*) from 表A where datediff(day,datefield,'2009-9-9')=0
--小F-- 2009-09-10
  • 打赏
  • 举报
回复
select count(1) FROM 表A where  datediff(dd,''2009-9-9' ',[time])=0

27,579

社区成员

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

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