27,580
社区成员
发帖
与我相关
我的任务
分享
select * from History where STime>='2011-12-1 00:00:00.000' and STime<='2011-12-1 23:59:59.997'
if object_id('tb','U') is not null
drop table tb
go
create table tb
(
id int identity(1,1),
name datetime
)
go
insert into tb (name)
select '2011-10-10 12:13:14' union all
select '2011-12-01 10:10:10' union all
select '2011-12-01 08:10:10' union all
select '2011-10-09 23:11:13'
go
select *,[转换日期]=convert(varchar(10),name,120) from tb where convert(varchar(10),name,120)= '2011-12-01'
go
--用convert把日期时间类型的yyyy-mm-dd hh:mm:ss 转换成yyyy-mm-dd的就可以比较了
select * from History where datediff(dd,STime,'2011-12-01')=0
select * from History where datediff(dd,STime,'2011-12-01')=0
--这样也可以,可以用到索引,好点
declare @dt datetime='2011-11-1'
select * from History where STime>=@dt and STime<dateadd(day,1,@dt)
select * from History where convert(varchar(10),STime,120)='2011-12-01'