본문 바로가기

database/mssql

초일/말일 구하기

DECLARE @IDATE varchar(8)

SET @IDATE = '20090102'

 

/* 말일구하기 */
SELECT Convert(Varchar, DATEADD(DAY,-DATEPART(DD,DATEADD(MONTH,1,@IDATE)),DATEADD(MONTH,1,@IDATE)), 112)

 

/* 초일구하기 */
SELECT Convert(Varchar, DATEADD(DAY,1,DATEADD(DAY,-DATEPART(DD,@IDATE),@IDATE)), 112)