SELECT GETDATE() as Today
SELECT DATEADD(d,-1,GETDATE()) AS Yesterday
SELECT DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0) AS FirstDayOfThisWeek
SELECT DATEADD(wk,DATEDIFF(wk,0,GETDATE()),6) AS LastDayOfThisWeek
SELECT DATEADD(wk,DATEDIFF(wk,7,GETDATE()),0) AS FirstDayOfLastWeek
SELECT DATEADD(wk,DATEDIFF(wk,7,GETDATE()),6) AS LastDayofLastWeek
SELECT DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0) AS FirstDayOfThisMonth
SELECT DATEADD(ms,- 3,DATEADD(mm,0,DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,0))) AS LastDayOfThisMonth
SELECT DATEADD(mm,-1,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)) AS FirstDayOfLastMonth
SELECT DATEADD(ms,-3,DATEADD(mm,0,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0))) AS LastDayOfLastMonth
SELECT DATEADD(q,DATEDIFF(q,0,GETDATE())-1,0) AS FirstDayOfLastFullQuarter
SELECT DATEADD(D, 0, DATEDIFF(D, 0, DATEADD(s,-1,DATEADD(q,1,DATEADD(q,DATEDIFF(q,0,GETDATE())-1,0))))) AS LastDayOfLastFullQuarter
SELECT DATEADD(q,DATEDIFF(q,0,GETDATE()),0) AS FirstDayOfThisQuarter
SELECT DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0) AS FirstDayOfThisYear
SELECT DATEADD(ms,-3,DATEADD(yy,0,DATEADD(yy,DATEDIFF(yy,0,GETDATE())+1,0))) AS LastDayOfThisYear
SELECT DATEADD(yy,-1,DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0)) AS FirstDayOfLastYear
SELECT DATEADD(ms,-3,DATEADD(yy,0,DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0))) AS LastDayOfLastYear
2015년 5월 26일 화요일
[MSSQL] 자주 사용하는 날자 함수 (frequently used data functions)
쿼리 작성시 자주 사용하는 날자 함수 만들기
피드 구독하기:
댓글 (Atom)
추천 게시물
python: SVD(Singular Value Decomposition)로 간단한 추천시스템 만들기( feat. surprise )
svd_example In [15]: # !pip install surprise In [21]: from...
댓글 없음:
댓글 쓰기