Get day of week in SQL Server 2005/2008(在 SQL Server 2005/2008 中获取星期几)
问题描述
如果我有一个日期 01/01/2009,我想知道它是哪一天,例如周一、周二等...
If I have a date 01/01/2009, I want to find out what day it was e.g. Monday, Tuesday, etc...
在 SQL Server 2005/2008 中是否有内置函数?还是需要用辅助表?
Is there a built-in function for this in SQL Server 2005/2008? Or do I need to use an auxiliary table?
推荐答案
使用 DATENAME
或 DATEPART
:
SELECT DATENAME(dw,GETDATE()) -- Friday
SELECT DATEPART(dw,GETDATE()) -- 6
这篇关于在 SQL Server 2005/2008 中获取星期几的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!