日期:2014-05-16  浏览次数:20908 次

也提一个时间问题,查询生日
如果有下表
staffInfo
(di                 int,
  name             varchar(30),
  birthdate   date
);
现在想查处本周内过生日的所有员工,今天可能是本周内的任何一天.提示
select       *       from      
staffInfo
where       datediff(wk,birdthdate,getdate())=0   ;
是在SQL   server下的.

------解决方案--------------------
select * from staffInfo where datepart=(week, birthdate)=datepart(week,getdate())
这个不行?
------解决方案--------------------
select *
from staffInfo
where datediff(week,birthdate,getdate())+datediff(week, '1900-1-1 ',birthdate)=datediff(week, '1900-1-1 ',getdate())
------解决方案--------------------
select * from staffInfo
where concat(year(now()), date_format(birthdate, "-%m-%d ") between curdate()- interval (dayofweek(curdate())-2) day
and curdate()+interval (8-dayofweek(curdate())) day

这个肯定行,效率吗,可能有点低
------解决方案--------------------
select * from
staffInfo
where date_format(now(), '%u ')=date_format(birdthdate, "%u ");