database/mssql

초일/말일 구하기

두억시니 2009. 11. 17. 19:03


1
2
3
4
5
6
7
8
9
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)
cs