티스토리 뷰
SELECT GETDATE(); --오늘날짜
SELECT CONVERT(CHAR(8), DATEADD(dd,-1,GETDATE()),112); --어제날짜
SELECT CONVERT(CHAR(8), DATEADD(dd,+1,GETDATE()),112); --내일날짜
SELECT CONVERT(CHAR(8), DATEADD(mm,+3, GETDATE()),112); -- 3달후날짜
SELECT CONVERT(CHAR(8), DATEADD(yy,+1, GETDATE()),112); -- 1년후오늘날짜
SELECT CONVERT(CHAR(8), DATEADD(mm, -1, GETDATE()-DAY(GETDATE()-1)),112); --지난달1일
SELECT CONVERT(CHAR(8), DATEADD(mm, 0, GETDATE()-DAY(GETDATE())),112); --지난달말일
SELECT CONVERT(CHAR(8), DATEADD(dd, 0, GETDATE()-DAY(GETDATE()-1)),112); --이번달1일
SELECT CONVERT(CHAR(8), DATEADD(mm, +1, GETDATE()-DAY(GETDATE())),112); --이번달말일
SELECT CONVERT(CHAR(8), DATEADD(MM, +1, GETDATE()-DAY(GETDATE()-1)),112); --다음달1일
SELECT CONVERT(CHAR(8), DATEADD(MM, +2, GETDATE()-DAY(GETDATE())),112); --다음달말일
SELECT CONVERT(CHAR(8), DATEADD(MM, -2, GETDATE()-DAY(GETDATE()-1)),112); -- 2달전1일
SELECT CONVERT(CHAR(8), DATEADD(MM, -1, GETDATE()-DAY(GETDATE())),112); --2달전말일
SELECT CONVERT(CHAR(8), DATEADD(YY, 0, GETDATE()-DATEPART(DAYOFYEAR, GETDATE()-1)),112); --올해1월1일
SELECT CONVERT(CHAR(8), DATEADD(YY, +1, GETDATE()-DATEPART(DAYOFYEAR, GETDATE())),112); --올해12월말일
SELECT CONVERT(CHAR(8), DATEADD(YY, +1, GETDATE()-DATEPART(DAYOFYEAR, GETDATE()-1)),112); --내년1월1일
SELECT CONVERT(CHAR(8), DATEADD(YY, +2, GETDATE()-DATEPART(DAYOFYEAR, GETDATE())),112); --내년12월말일
SELECT DATEPART(DAYOFYEAR,'2010-07-20'); -- 2010-01-01 ~ 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 '일요일'
WHEN '2' THEN '월요일'
WHEN '3' THEN '화요일'
WHEN '4' THEN '수요일'
WHEN '5' THEN '목요일'
WHEN '6' THEN '금요일'
ELSE '토요일'
END AS '요일';
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) + '년' + substring(@_date,5,2) +'월' + substring(@_date,7,2) + '일입니다'
,CONVERT(VARCHAR, DATEPART(WEEK, @_date))+'번째주입니다'
,CONVERT(VARCHAR, DATEPART(dayofyear, @_date))+'번째날짜입니다.';
DECLARE @_date DATETIME;
SET @_date = CONVERT(CHAR(8), REPLACE('2010-07-20','-',''),112);
SELECT CONVERT(CHAR(4),DATEPART(YEAR,@_date)) + '년' ,CONVERT(CHAR(2),DATEPART(MONTH,@_date))+'월', CONVERT(CHAR(2),DATEPART(DAY,@_date))+'일';
SELECT CONVERT(VARCHAR, DATEPART(WEEK, @_date))+'번째주입니다'
,CONVERT(VARCHAR, DATEPART(dayofyear, @_date))+'번째날짜입니다.';
참조 - http://dramatic.tistory.com/13
'Database' 카테고리의 다른 글
[MS SQL] Lock 해결 (0) | 2011.03.16 |
---|---|
[MSSQL]CHARINDEX,LEFT (0) | 2011.02.18 |
[ORACLE]개행문자(\r\n) 제거하기 (0) | 2011.01.25 |
[ORACLE] 문자열에서 특정 문자 갯수 알아보기. (0) | 2010.12.14 |
[ORACLE] 중복카운트수 찾기, 대소문자 구별 (0) | 2010.12.10 |
- Total
- Today
- Yesterday
- 데이터
- Toad
- 테이블
- MySQL
- 백업
- 자동차
- user
- IP
- 파일
- tomcat
- delete
- 리눅스
- Windows
- mssql
- select
- 서버
- 오라클
- Oracle
- table
- apache
- java
- server
- DB
- sql
- 윈도우
- 설정
- eclipse
- Linux
- DATABASE
- Shell
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |