Sql获取当前日期是星期几的代码总结

1》select datepart(weekday,getdate())

这个是返回的星期几的整数值哟!

2》select   DATENAME(weekday,getdate())

这个比较方便了,直接返回字符型的星期几,如今天是星期二,就直接输入星期二了

注:如果获取日期的字段为短整形,如2010-1-12,获取的星期可能就不正确了哟!

3》select a as 星期, getdate() as 日期
from(select a='星期一',b=1
  union all select '星期二',2 union all select '星期三',3
  union all select '星期四',4 union all select '星期五',5
  union all select '星期六',6 union all select '星期日',0
)a where b = (datepart(weekday,getdate())-1)

这个方法代码稍微多了点,但也能实现相应的功能了!

posted on 2010-03-08 14:46  ★金★  阅读(6911)  评论(0编辑  收藏  举报

导航