convert函式:
作用:
- convert()函式是把日期轉換為新資料型別的通用函式,
- convert() 函式可以用不同的格式顯示日期/時間資料,
語法:
CONVERT(data_type(length),expression,style)
引數:data_type(length):目標資料型別(長度)
expression:需要轉換的資料
style:規定日期/時間的輸出格式
style規定輸出的格式:
| 引數 | 結果 |
| 0/100 | 12 31 2020 8:40AM |
|
1 101 |
04/22/20 04/22/2020 |
|
2 102 |
20.12.31 2020.12.31 |
|
3 103 |
31/12/20 31/12/2020 |
|
4 104 |
31.12.20 31.12.2020 |
|
5 105 |
31-12-20 31-12-2020 |
|
6 106 |
31 12 20 31 12 2020 |
|
7 107 |
12 31,20 12 31,2020 |
|
8/108 |
09:28:24 |
|
9/109 |
12 31 2020 8:40:37:890AM |
|
10 110 |
12-31-20 12-31-2020 |
|
11 111 |
20/12/31 2020/12/31 |
|
12 112 |
201231 20201231 |
|
13/113 |
31 12 2020 12:31:46:780 |
| 14/114 | 12:33:12:250 |
| 20/120 |
2020-12-31 12:46:44 |
| 21/121 |
2020-12-31 12:48:41.437 |
| 22 |
12/31/20 12:50:59 PM |
| 23 |
2020-12-31 |
| 24 | 12:54:03 |
| 25 | 2020-12-31 13:11:21.107 |
| 126/127 | 2020-12-31T13:35:08.250 |
在SQLServer中的getdate()函式可以獲取系統當前日期.
select Convert(Varchar(30),getdate(),0) as date; 12 31 2020 8:40AM (月 日 年 時間AM/PM)
select Convert(Varchar(30),getdate(),100) as date;
select Convert(varchar(30),getdate(),1) as date; 04/22/20 (月/日/年)
select Convert(Varchar(30),getdate(),101) as date; 04/22/2020
select Convert(Varchar(30),getdate(),2) as date; 20.12.31 (年.月.日)
select Convert(Varchar(30),getdate(),102) as date; 2020.12.31
select Convert(Varchar(30),getdate(),3) as date; 31/12/20 (日/月/年)
select Convert(Varchar(30),getdate(),103) as date; 31/12/2020
select Convert(Varchar(30),getdate(),4) as date; 31.12.20 (日.月.年)
select Convert(Varchar(30),getdate(),104) as date; 31.12.2020
select Convert(Varchar(30),getdate(),5) as date; 31-12-20 (日-月-年)
select Convert(Varchar(30),getdate(),105) as date; 31-12-2020
select Convert(Varchar(30),getdate(),6) as date; 31 12 20 (日 月 年)
select Convert(Varchar(30),getdate(),106) as date; 31 12 2020
select Convert(Varchar(30),getdate(),7) as date; 12 31,20 (月 日,年)
select Convert(Varchar(30),getdate(),107) as date; 12 31,2020
select Convert(Varchar(30),getdate(),8) as date; 09:28:24 (時:分:秒)
select Convert(Varchar(30),getdate(),108) as date;
select Convert(Varchar(30),getdate(),9) as date; 12 31 2020 8:40:37:890AM (月 日 年 時間AM/PM)
select Convert(Varchar(30),getdate(),109) as date;
select Convert(Varchar(30),getdate(),10) as date; 12-31-20 (月-日-年)
select Convert(Varchar(30),getdate(),110) as date; 12-31-2020
select Convert(Varchar(30),getdate(),11) as date; 20/12/31 (年/月/日)
select Convert(Varchar(30),getdate(),111) as date; 2020/12/31
select Convert(Varchar(30),getdate(),12) as date; 201231 (年月日)
select Convert(Varchar(30),getdate(),112) as date; 20201231
select Convert(Varchar(30),getdate(),13) as date; 31 12 2020 12:31:46:780 (日 月 年 時間)
select Convert(Varchar(30),getdate(),113) as date;
select Convert(Varchar(30),getdate(),14) as date; 12:33:12:250 (時間)
select Convert(Varchar(30),getdate(),114) as date;
select Convert(Varchar(30),getdate(),20) as date; 2020-12-31 12:46:44 (年-月-日 時:分:秒)
select Convert(Varchar(30),getdate(),120) as date;
select Convert(Varchar(30),getdate(),21) as date; 2020-12-31 12:48:41.437 (年-月-日 時間)
select Convert(Varchar(30),getdate(),121) as date;
select Convert(Varchar(30),getdate(),22) as date; 12/31/20 12:50:59 PM (月/日/年 時:分:秒 AM/PM)
select Convert(Varchar(30),getdate(),23) as date; 2020-12-31 (年-月-日)
select Convert(Varchar(30),getdate(),24) as date; 12:54:03 (時:分:秒)
select Convert(Varchar(30),getdate(),25) as date; 2020-12-31 13:11:21.107 (年-月-日 時間)
select Convert(Varchar(30),getdate(),126) as date; 2020-12-31T13:35:08.250
select Convert(Varchar(30),getdate(),127) as date;
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/244660.html
標籤:SQL Server
