求一判断时间的语句,该如何处理
求一判断时间的语句
我想根据条件清空或者更新数据库里面的数据
条件是当前日期或者时间是否属于本月、本周、本日
请问怎样判断当前日期或者时间是否属于本月、本周、本日?
------解决方案--------------------
select datepart(month,getdate()) as 月
,datepart(week,getdate()) as 第幾周
,datepart(day,getdate()) as 日
,datepart(year,getdate()) as 年
,datepart(weekday,getdate()) as 星期幾
/*
月 第幾周 日 年 星期幾
----------- ----------- ----------- ----------- -----------
10 43 26 2007 6
*/
------解决方案--------------------
select * from tb where datepart(month,时间字段,getdate()) = 0 --月
select * from tb where datepart(week,时间字段,getdate()) = 0 --周
select * from tb where datepart(day,时间字段,getdate()) = 0 --日
------解决方案--------------------
我想根据条件清空或者更新数据库里面的数据
条件是当前日期或者时间是否属于本月、本周、本日
请问怎样判断当前日期或者时间是否属于本月、本周、本日?
------解决方案--------------------
select datepart(month,getdate()) as 月
,datepart(week,getdate()) as 第幾周
,datepart(day,getdate()) as 日
,datepart(year,getdate()) as 年
,datepart(weekday,getdate()) as 星期幾
/*
月 第幾周 日 年 星期幾
----------- ----------- ----------- ----------- -----------
10 43 26 2007 6
*/
------解决方案--------------------
select * from tb where datepart(month,时间字段,getdate()) = 0 --月
select * from tb where datepart(week,时间字段,getdate()) = 0 --周
select * from tb where datepart(day,时间字段,getdate()) = 0 --日
------解决方案--------------------
- SQL code
--判断是否本月 datediff(mm,日期字段,getdate())=0 --判断是否本周 datediff(dw,日期字段,getdate())=0 --判断是否本日 即同一天 datediff(dd,日期字段,getdate())=0
------解决方案--------------------
- SQL code
declare @t datetime set @t ='2007-01-01' print year(@t) print month(@t) print day(@t) /* 2007 1 1 */ update t set aa='aa' where year(@t)=year(getdate()) and month(@t)==month(getdate()) and day(@t)=day(getdate())