>  기사  >  php教程  >  SQL에서 CONVERT 변환 함수 사용

SQL에서 CONVERT 변환 함수 사용

高洛峰
高洛峰원래의
2016-12-14 13:17:211220검색

형식:
CONVERT(data_type,expression[,style])

설명:
이 스타일은 일반적으로 시간 유형(datetime, smalldatetime)과 문자열 유형(nchar, nvarchar, char ,varchar)
은 서로 변환할 때만 사용됩니다.

예:
SELECT CONVERT(varchar(30),getdate(),101) now
결과는 다음과 같습니다.
지금
--------------------------------------------
|2001년 9월 15일

===================================== ======== =======================

시간을 환산할 때 스타일 번호의 의미는 다음과 같습니다.

---- ---------------------------- ---------- -------------- ---------- ----
스타일(연도 2자리) | 스타일(연도 4자리) | 입력 및 출력 형식                           --------- -------------------------- ----------- --------------------------
0                                                                                           (또는 PM )                                               ---------------- --------------------- ---------------
1                                                                                                              >                       --- ------------------------------- ------ --------------------------
2                                                                               - dd                                                                                     ------------------------------------------------- - -------------
3                                                                                                        >--------- ---------- --------------------------- ---------- -----------------
4                                                                                             
------------- ------------------------ ------------- ------------------------ ----------
5                              |  105    의미대명             |   dd-mm-yy                                      
----------------------------- ------------------------------------- ---
6                               |  106                           |   dd mon yy                                      
------------------------------- ------------------------------------- --------------
7                             |  107                           |   월 dd,yy                                      
------------------ ------------------------------------- ---------------
8                              |  108                           |   hh:mm:ss                                      
----------------------------- ------------------------------------- ---
9                               |  109                           |   월 일 yyyy hh:mi:ss:mmmmAM(或PM)
--------------------------------- ------------------------------------- -------------------------
10                            |  110    미국                 |   mm-dd-yy                                      
----------------------------- ------------------------------------- ---
11                             |  111    日本                 |   yy/mm/dd                                     
----------------------------- ------------------------------------- ---
13           ------------------------------------ - ------------------
13 | 113 유럽 기본값 | dd mon yyyy hh:mi:ss:mmm (24시간 형식)
-- --- ---------------------------------- --- ---------------------------------- --- ---
14                                                                                                                                                                                                           ----------------------------------------- ---------- ---------------------
20                                                                      :ss (24시간 형식)
----------------------------- ------------------------------------------------- - -----------------
21                                                                                                                                     --------------- -------- ---------------- --------------------- ---

문 및 쿼리 결과:
SELECT CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 오전 10:57
SELECT CONVERT(varchar(100), GETDATE (), 1): 05/16/06
SELECT CONVERT(varchar(100), GETDATE(), 2): 06.05.16
SELECT CONVERT(varchar(100), GETDATE(), 3): 16/05/06
SELECT CONVERT(varchar(100), GETDATE(), 4): 16.05.06
SELECT CONVERT(varchar(100), GETDATE(), 5): 16-05-06
SELECT CONVERT(varchar(100), GETDATE(), 6): 16 05 06
SELECT CONVERT(varchar(100) ), GETDATE(), 7): 05 16, 06
SELECT CONVERT(varchar( 100), GETDATE(), 8): 10:57:46
SELECT CONVERT(varchar(100), GETDATE() , 9): 05 16 2006 10:57:46:827AM
SELECT CONVERT(varchar (100), GETDATE(), 10): 05-16-06
SELECT CONVERT(varchar(100), GETDATE( ), 11): 06/05/16
SELECT CONVERT(varchar(100), GETDATE(), 12): 060516
SELECT CONVERT(varchar(100), GETDATE(), 13): 16 05 2006 10:57:46:937
SELECT CONVERT(varchar(100), GETDATE() , 14): 10:57:46:967
SELECT CONVERT(varchar(100), GETDATE(), 20): 2006-05-16 10:57:47
SELECT CONVERT(varchar(100), GETDATE(), 21): 2006-05-16 10:57:47.157
SELECT CONVERT(varchar(100), GETDATE (), 22): 05/16/06 오전 10:57:47
SELECT CONVERT(varchar(100), GETDATE(), 23): 2006-05-16
SELECT CONVERT(varchar(100) , GETDATE(), 24): 10:57:47
SELECT CONVERT(varchar( 100), GETDATE(), 25): 2006-05-16 10:57:47.250
SELECT CONVERT(varchar(100) ), GETDATE(), 100): 05 16 2006 오전 10:57
SELECT CONVERT( varchar(100), GETDATE(), 101): 05/16/2006
SELECT CONVERT(varchar(100), GETDATE(), 102): 2006.05.16
SELECT CONVERT(varchar(100), GETDATE(), 103): 16/05/2006
SELECT CONVERT(varchar(100 ), GETDATE(), 104): 16.05.2006
SELECT CONVERT(varchar(100), GETDATE(), 105): 16-05-2006
SELECT CONVERT(varchar(100), GETDATE(), 106): 16 05 2006
SELECT CONVERT(varchar(100), GETDATE(), 107): 05 16, 2006
SELECT CONVERT(varchar(100), GETDATE(), 108): 10:57: 49
SELECT CONVERT(varchar(100), GETDATE(), 109): 05 16 2006 10:57:49:437AM
SELECT CONVERT(varchar(100), GETDATE(), 110): 05-16 -2006
SELECT CONVERT(varchar(100), GETDATE(), 111): 2006/05/16
SELECT CONVERT(varchar(100), GETDATE(), 112): 20060516
SELECT CONVERT( varchar(100), GETDATE(), 113): 16 05 2006 10:57:49:513
SELECT CONVERT(varchar(100), GETDATE(), 114): 10:57:49:547
SELECT CONVERT(varchar(100), GETDATE(), 120): 2006-05-16 10:57:49
SELECT CONVERT(varchar(100), GETDATE(), 121): 2006-05-16 10: 57:49:000

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.