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)
這個方法代碼稍微多了點,但也能實現相應的功能了!
