convert函数: 作用:
语法: CONVERT(data_type(length),expression,style) 参数:data_type(length):目标数据类型(长度) expression:需要转换的数据 style:规定日期/时间的输出格式 style规定输出的格式:
在SQLServer中的getdate()函数可以获取系统当前日期.
select Convert(Varchar(30),getdate(),0) as date; 12 31 2020 8:40AM (月 日 年 时间AM/PM)
select Convert(varchar(30),getdate(),1) as date; 04/22/20 (月/日/年)
select Convert(Varchar(30),getdate(),2) as date; 20.12.31 (年.月.日) select Convert(Varchar(30),getdate(),3) as date; 31/12/20 (日/月/年)
select Convert(Varchar(30),getdate(),4) as date; 31.12.20 (日.月.年)
select Convert(Varchar(30),getdate(),5) as date; 31-12-20 (日-月-年)
select Convert(Varchar(30),getdate(),6) as date; 31 12 20 (日 月 年)
select Convert(Varchar(30),getdate(),7) as date; 12 31,20 (月 日,年)
select Convert(Varchar(30),getdate(),8) as date; 09:28:24 (时:分:秒)
select Convert(Varchar(30),getdate(),9) as date; 12 31 2020 8:40:37:890AM (月 日 年 时间AM/PM)
select Convert(Varchar(30),getdate(),10) as date; 12-31-20 (月-日-年)
select Convert(Varchar(30),getdate(),11) as date; 20/12/31 (年/月/日)
select Convert(Varchar(30),getdate(),12) as date; 201231 (年月日)
select Convert(Varchar(30),getdate(),13) as date; 31 12 2020 12:31:46:780 (日 月 年 时间)
select Convert(Varchar(30),getdate(),14) as date; 12:33:12:250 (时间)
select Convert(Varchar(30),getdate(),20) as date; 2020-12-31 12:46:44 (年-月-日 时:分:秒)
select Convert(Varchar(30),getdate(),21) as date; 2020-12-31 12:48:41.437 (年-月-日 时间)
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 |
|
来自: python_lover > 《待分类》