728x90
반응형
MSSQL 날짜형식
MSSQL 날짜 변환표 (기준날짜를 대상으로 CONVERT 실행하여 날짜 형변환)
쿼리 | 결과 | 코드 |
CONVERT(CHAR(19), DATETIME, 0) | 01 02 2000 1:14PM | MM DD YYYY H:MM |
CONVERT(CHAR(10), DATETIME, 1) | 01/02/2000 | MM/DD/YYYY |
CONVERT(CHAR(8), DATETIME, 2) | 00.01.02 | YY.MM.DD |
CONVERT(CHAR(8), DATETIME, 3) | 02/01/00 | DD/MM/YY |
CONVERT(CHAR(8), DATETIME, 4) | 02.01.00 | DD.MM.YY |
CONVERT(CHAR(8), DATETIME, 5) | 02-01-00 | DD-MM-YY |
CONVERT(CHAR(8), DATETIME, 6) | 02 01 00 | DD MM YY |
CONVERT(CHAR(9), DATETIME, 7) | 01 02, 00 | MM DD, YY |
CONVERT(CHAR(8), DATETIME, 8) | 13:14:15 | HH:MM:SS |
CONVERT(CHAR(26), DATETIME, 9) | 01 02 2000 1:14:15.678PM | NN DD YYYY H:MM:SS.MS |
CONVERT(CHAR(8), DATETIME, 10) | 01-02-00 | MM-DD-YY |
CONVERT(CHAR(8), DATETIME, 11) | 02/01/00 | DD/MM/YY |
CONVERT(CHAR(6), DATETIME, 12) | 000102 | YYMMDD |
CONVERT(CHAR(24), DATETIME, 13) | 02 01 2000 13:14:15.678 | DD MM YYYY HH:MM:SS.MS |
CONVERT(CHAR(12), DATETIME, 14) | 13:14:15.678 | HH:MM:SS.MS |
CONVERT(CHAR(19), DATETIME, 20) | 2000-01-02 13:14:15 | YYYY-MM-DD HH:MM:SS |
CONVERT(CHAR(23), DATETIME, 21) | 2000-01-02 13:14:15.678 | YYYY-MM-DD HH:MM:SS.MS |
CONVERT(CHAR(20), DATETIME, 22) | 01/02/00 1:14:15 PM | MM/DD/YY H:M:S |
CONVERT(CHAR(10), DATETIME, 23) | 2000-01-02 | YYYY-MM-DD |
CONVERT(CHAR(8), DATETIME, 24) | 13:14:15 | HH:MM:SS |
CONVERT(CHAR(23), DATETIME, 25) | 2000-01-02 13:14:15.678 | YYYY-MM-DD HH:MM:SS.MS |
CONVERT(CHAR(19), DATETIME, 100) | 01 02 2000 1:02PM | MM DD YYYY H:MM |
CONVERT(CHAR(10), DATETIME, 101) | 01/02/2000 | MM/DD/YYYY |
CONVERT(CHAR(10), DATETIME, 102) | 2000.01.02 | YYYY.MM.DD |
CONVERT(CHAR(10), DATETIME, 103) | 02/01/2000 | DD/MM/YYYY |
CONVERT(CHAR(10), DATETIME, 104) | 02/01/2000 | DD/MM/YYYY |
CONVERT(CHAR(10), DATETIME, 105) | 02-01-2000 | DD-MM-YYYY |
CONVERT(CHAR(11), DATETIME, 106) | 02 01 2000 | DD MM YYYY |
CONVERT(CHAR(12), DATETIME, 107) | 01 02, 2000 | MM DD, YYYY |
CONVERT(CHAR(8), DATETIME, 108) | 13:14:15 | HH:MM:SS |
CONVERT(CHAR(26), DATETIME, 109) | 01 02 2000 1:14:15.678PM | MM DD YYYY H:MM:DD.MS |
CONVERT(CHAR(10), DATETIME, 110) | 01-02-2000 | MM-DD-YYYY |
CONVERT(CHAR(10), DATETIME, 111) | 2000/01/02 | YYYY/MM/DD |
CONVERT(CHAR(8), DATETIME, 112) | 20000102 | YYYYMMDD |
CONVERT(CHAR(24), DATETIME, 113) | 02 01 2000 13:14:15.678 | DD MM YYYY HH:MM:DD.MS |
CONVERT(CHAR(12), DATETIME, 114) | 13:14:15:678 | HH:MM:DD:MS |
CONVERT(CHAR(19), DATETIME, 120) | 2000-01-02 13:14:15 | YYYY-MM-DD HH:MM:SS |
CONVERT(CHAR(23), DATETIME, 121) | 2000-01-02 13:14:15.678 | YYYY-MM-DD HH:MM:SS.MS |
CONVERT(CHAR(23), DATETIME, 126) | 2000-01-02T13:14:15.678 | YYYY-MM-DDT HH:MM:SS.MS |
CONVERT(CHAR(23), DATETIME, 127) | 2000-01-02T13:14:15.678 | YYYY-MM-DDT HH:MM:SS.MS |
CONVERT(CHAR(25), DATETIME, 131) | 1/06/1421 1:13:14:678PM |
[참고사항] 자주 쓰이는 변환표
번호 | 쿼리 | 결과 | 코드 |
21 | CONVERT(CHAR(23), DATETIME, 21) | 2000-01-02 13:14:15.678 | YYYY-MM-DD HH:MM:SS.MS |
23 | CONVERT(CHAR(10), DATETIME, 23) | 2000-01-02 | YYYY-MM-DD |
112 | CONVERT(CHAR(8), DATETIME, 112) | 20000102 | YYYYMMDD |
예제 1
오늘 날짜를 YYYY-MM-DD 형태로 CONVERT를 이용하여 표시하시오.
(2000년 01월 02일 13시 14분 15초 기준)
예제 1 쿼리
SELECT CONVERT(CHAR(10), GETDATE(), 23) AS 날짜
날짜
2000-01-02
예제 2
오늘 날짜를 YYYY-MM-DD HH:MM:SS.MS 형태로 CONVERT를 이용하여 표시하시오
. (2000년 01월 02일 13시 14분 15초 기준)
- 예제 2 쿼리
SELECT CONVERT(CHAR(23), GETDATE(), 21) AS 날짜
날짜
2000-01-02 13:14:15.678
728x90
반응형
'데이터베이스 > MS-SQL' 카테고리의 다른 글
MSSQL BETWEEN 사용하기 (0) | 2023.01.26 |
---|---|
MSSQL에서 특정 문자의 갯수 알기 (0) | 2023.01.25 |
형변환 마스킹 (0) | 2023.01.18 |
임시테이블 활용/Auto Commit/날짜 변환 (0) | 2023.01.12 |
갯수 지정해서 값 가져오기 (0) | 2023.01.09 |
댓글