일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- 전남 고속도로 휴게소
- 경기
- 광주
- 대전
- 전남
- 강원
- 전기자동차 충전소
- 경남
- 경기 고속도로 휴게소
- EBS 구독
- 대구
- 제주
- 인천
- centos resolution
- 군부대
- 김해 손수제비
- 부산
- 서울
- 충남 고속도로 휴게소
- 울산
- 송정물총칼국수
- 무궁화양분식
- 경남 고속도로 휴게소
- 충남
- 전북
- 전북 고속도로 휴게소
- 경북 고속도로 휴게소
- 충북 고속도로 휴게소
- 경북
- 충북
- Today
- Total
정보 도우미
mssql date function 본문
SELECT GETDATE(); --today
SELECT CONVERT(CHAR(8), DATEADD(dd,-1,GETDATE()),112); -- yesterday
SELECT CONVERT(CHAR(8), DATEADD(dd,+1,GETDATE()),112); --tomorrow
SELECT CONVERT(CHAR(8), DATEADD(mm,+3, GETDATE()),112); -- next 3 month
SELECT CONVERT(CHAR(8), DATEADD(yy,+1, GETDATE()),112); -- next 1 year
SELECT CONVERT(CHAR(8), DATEADD(mm, -1, GETDATE()-DAY(GETDATE()-1)),112); -- before 1 month
SELECT CONVERT(CHAR(8), DATEADD(mm, 0, GETDATE()-DAY(GETDATE())),112); -- last day of before 1 month
SELECT CONVERT(CHAR(8), DATEADD(dd, 0, GETDATE()-DAY(GETDATE()-1)),112); --first day of a month
SELECT CONVERT(CHAR(8), DATEADD(mm, +1, GETDATE()-DAY(GETDATE())),112); --last day of a month
SELECT CONVERT(CHAR(8), DATEADD(MM, +1, GETDATE()-DAY(GETDATE()-1)),112); --first day of next month
SELECT CONVERT(CHAR(8), DATEADD(MM, +2, GETDATE()-DAY(GETDATE())),112); -- last day of next month
SELECT CONVERT(CHAR(8), DATEADD(MM, -2, GETDATE()-DAY(GETDATE()-1)),112); -- first day of before 2 month
SELECT CONVERT(CHAR(8), DATEADD(MM, -1, GETDATE()-DAY(GETDATE())),112); --last day of before 2 month
SELECT CONVERT(CHAR(8), DATEADD(YY, 0, GETDATE()-DATEPART(DAYOFYEAR, GETDATE()-1)),112); -- first day of a year
SELECT CONVERT(CHAR(8), DATEADD(YY, +1, GETDATE()-DATEPART(DAYOFYEAR, GETDATE())),112); -- last day of a year
SELECT CONVERT(CHAR(8), DATEADD(YY, +1, GETDATE()-DATEPART(DAYOFYEAR, GETDATE()-1)),112); --first day of next year
SELECT CONVERT(CHAR(8), DATEADD(YY, +2, GETDATE()-DATEPART(DAYOFYEAR, GETDATE())),112); --last day of next year
SELECT DATEPART(DAYOFYEAR,'2010-07-20'); -- days of between 2010-01-01 and 2010-07-02
SELECT DATEPART(WEEK, '2010-07-20');
SELECT DATEPART(WEEKDAY, '2010-07-20');
DECLARE @WEEK_DAY DATETIME;
SET @WEEK_DAY = '2010-08-15';
SELECT
CASE DATEPART(WEEKDAY, @WEEK_DAY) WHEN '1' THEN 'sun'
WHEN '2' THEN 'mon'
WHEN '3' THEN 'tue'
WHEN '4' THEN 'wed'
WHEN '5' THEN 'tur'
WHEN '6' THEN 'fri'
ELSE 'sat'
END AS 'day';
SELECT DATEPART(DAYOFYEAR, '2010-08-15');
SELECT DATEPART(WEEK, '2010-08-15');
DECLARE @_date CHAR(8);
SET @_date = REPLACE('2010-07-20','-','');
SELECT SUBSTRING(@_date,1,4) + 'year' + substring(@_date,5,2) +'month' + substring(@_date,7,2) + 'day'
,CONVERT(VARCHAR, DATEPART(WEEK, @_date))+'th weeks'
,CONVERT(VARCHAR, DATEPART(dayofyear, @_date))+'th days';
DECLARE @_date DATETIME;
SET @_date = CONVERT(CHAR(8), REPLACE('2010-07-20','-',''),112);
SELECT CONVERT(CHAR(4),DATEPART(YEAR,@_date)) + 'year' ,CONVERT(CHAR(2),DATEPART(MONTH,@_date))+'month', CONVERT(CHAR(2),DATEPART(DAY,@_date))+'day';
SELECT CONVERT(VARCHAR, DATEPART(WEEK, @_date))+'th weeks'
,CONVERT(VARCHAR, DATEPART(dayofyear, @_date))+'th days';
'Database > MSSQL' 카테고리의 다른 글
MSSQL 컬럼명 포함한 테이블 검색 쿼리 (0) | 2015.12.15 |
---|