存储过程里面的时间 怎么对比 是不是今天和是不是 这个月?

我现在有一张表 里面记录了 一个datetime

然后 我存储过程里面如何 用 getdate() 跟他对比 是不是今天 和 是不是这个月呢??

求解 看到存储过程就蛋疼。。。。

作者: lijing3333   发布时间: 2011-06-09

datediff (day, [datetime],getdate()) =0 今天
datediff (month, [datetime], getdate())=0 当月

作者: playwarcraft   发布时间: 2011-06-09

datediff(dd,datetimecol,getdate()) = 0 --天
datediff(mm,datetimecol,getdate()) = 0 --月

作者: OrchidCat   发布时间: 2011-06-09

SQL code
--今天
where col >= convert(varchar(10),getdate(),120) and col < convert(varchar(10),dateadd(day,1,getdate()),120)

--本月
where col >= convert(varchar(7),getdate(),120)+ '-01' and col < convert(varchar(7),dateadd(month,1,getdate()),120) + '-01'

作者: P1mm   发布时间: 2011-06-09

在字段用datediff 往往效率较低,如果数据量大还是用>=和<高效

作者: P1mm   发布时间: 2011-06-09

SQL code
datediff(dd,datetimecol,getdate()) = 0 --同一天
datediff(mm,datetimecol,getdate()) = 0 --同一月

作者: abcjun188   发布时间: 2011-06-09