DAY 6
0
Data Technology

# 語法說明

``````DATENAME ( 時間單位, date )
``````

``````SELECT DATENAME ( WEEKDAY,'2017-12-24 14:09:54.593')
``````

``````DATEPART( 時間單位, date )
``````

``````SELECT DATEPART(DW, '2017-12-24 14:09:54.593')
``````

``````DECLARE @today DATETIMEOFFSET = SYSDATETIMEOFFSET()
DECLARE @thisMonday DATETIMEOFFSET = DATEADD(ww, DATEDIFF(ww, 0, @today ) -1, 0)
DECLARE @nextMonday DATETIMEOFFSET = DATEADD(ww, DATEDIFF(ww, '', @today ) , '')

SELECT @today AS 'Today'
SELECT @thisMonday 'This Monday'
SELECT @nextMonday'Next Moday'
``````

``````DECLARE @today DATETIMEOFFSET = SYSDATETIMEOFFSET()
DECLARE @thisMonthFirstDay DATETIMEOFFSET = DATEADD(month, DATEDIFF(month, 0, @today) , 0)
DECLARE @nextMonthFirstDay DATETIMEOFFSET = DATEADD(month, DATEDIFF(month, 0, @today) +1 , 0)

SELECT @today AS 'Today'
SELECT @thisMonthFirstDay 'This Month First Day'
SELECT @nextMonthFirstDay 'Next Month First Day'
``````

``````DECLARE @today DATETIMEOFFSET = SYSDATETIMEOFFSET()
DECLARE @thisYearFirstDay DATETIMEOFFSET = DATEADD(year, DATEDIFF(year, 0, @today ) , 0)
DECLARE @nextYearFirstDay DATETIMEOFFSET = DATEADD(year, DATEDIFF(year, 0, @today ) +1 , 0)

SELECT @today AS 'Today'
SELECT @thisYearFirstDay 'This Year First Day'
SELECT @nextYearFirstDay 'Next Year First Day'
``````

SQL Server 學習日誌30