sql server汉语版的暗中同意的日子字段datetime格式是yyyy-mm-dd
thh:mm:ss.mmm比如:select getdate(State of Qatar二零零四-09-12 11:06:08.177整合治理了一下sql
server里面或许时时会用到的日期格式转变方法:比如如下:select
convert(varchar, getdate(卡塔尔, 120 卡塔尔(قطر‎二零零二-09-12 11:06:08select
convert(varchar(100卡塔尔(قطر‎, getdate(卡塔尔, 0State of Qatar: 05 16 二〇〇五 10:57amselect
convert(varchar(100State of Qatar, getdate(卡塔尔, 1卡塔尔: 05/16/06select
convert(varchar(100卡塔尔(قطر‎, getdate(卡塔尔(قطر‎, 2卡塔尔国: 06.05.16select
convert(varchar(100卡塔尔, getdate(卡塔尔(قطر‎, 3卡塔尔: 16/05/06select
convert(varchar(100卡塔尔(قطر‎, getdate(State of Qatar, 4卡塔尔国: 16.05.06select
convert(varchar(100卡塔尔国, getdate(卡塔尔(قطر‎, 5State of Qatar: 16-05-06select
convert(varchar(100卡塔尔国, getdate(State of Qatar, 6卡塔尔(قطر‎: 16 05 06select
convert(varchar(100State of Qatar, getdate(卡塔尔(قطر‎, 7State of Qatar: 05 16, 06select
convert(varchar(100卡塔尔, getdate(卡塔尔国, 8卡塔尔(قطر‎: 10:57:46select
convert(varchar(100卡塔尔, getdate(卡塔尔国, 9卡塔尔国: 05 16 二〇〇六 10:57:46:827amselect
convert(varchar(100State of Qatar, getdate(卡塔尔国, 10卡塔尔: 05-16-06select
convert(varchar(100卡塔尔(قطر‎, getdate(卡塔尔(قطر‎, 11卡塔尔(قطر‎: 06/05/16select
convert(varchar(100卡塔尔国, getdate(State of Qatar, 12State of Qatar: 060516select convert(varchar(100State of Qatar,
getdate(卡塔尔国, 13卡塔尔国: 16 05 二零零七 10:57:46:937select convert(varchar(100卡塔尔(قطر‎,
getdate(State of Qatar, 14卡塔尔(قطر‎: 10:57:46:967select convert(varchar(100卡塔尔, getdate(卡塔尔, 20卡塔尔国:
2007-05-16 10:57:47select convert(varchar(100), getdate(卡塔尔国, 21卡塔尔国:
2005-05-16 10:57:47.157select convert(varchar(100State of Qatar, getdate(State of Qatar, 22卡塔尔国:
05/16/06 10:57:47 amselect convert(varchar(100卡塔尔(قطر‎, getdate(State of Qatar, 23卡塔尔(قطر‎:
二〇〇七-05-16select convert(varchar(100卡塔尔(قطر‎, getdate(State of Qatar, 24卡塔尔: 10:57:47select
convert(varchar(100卡塔尔, getdate(卡塔尔, 25卡塔尔(قطر‎: 2005-05-16 10:57:47.250select
convert(varchar(100State of Qatar, getdate(卡塔尔国, 100卡塔尔(قطر‎: 05 16 二〇〇六 10:57amselect
convert(varchar(100State of Qatar, getdate(State of Qatar, 101State of Qatar: 05/16/二零零五select
convert(varchar(100卡塔尔国, getdate(卡塔尔(قطر‎, 102卡塔尔(قطر‎: 二零零七.05.16select
convert(varchar(100卡塔尔(قطر‎, getdate(State of Qatar, 103卡塔尔: 16/05/二零零七select
convert(varchar(100State of Qatar, getdate(卡塔尔国, 104卡塔尔: 16.05.2007select
convert(varchar(100卡塔尔国, getdate(卡塔尔国, 105State of Qatar: 16-05-二〇〇五select
convert(varchar(100卡塔尔, getdate(State of Qatar, 106卡塔尔: 16 05 2005select
convert(varchar(100State of Qatar, getdate(卡塔尔国, 107卡塔尔国: 05 16, 2005select
convert(varchar(100卡塔尔, getdate(卡塔尔, 108卡塔尔国: 10:57:49select
convert(varchar(100卡塔尔国, getdate(卡塔尔国, 109卡塔尔(قطر‎: 05 16 二零零七 10:57:49:437amselect
convert(varchar(100卡塔尔国, getdate(State of Qatar, 110State of Qatar: 05-16-二〇〇六select
convert(varchar(100卡塔尔, getdate(卡塔尔(قطر‎, 111卡塔尔国: 二零零七/05/16select
convert(varchar(100卡塔尔, getdate(State of Qatar, 112卡塔尔国: 二零零七0516select
convert(varchar(100卡塔尔, getdate(卡塔尔(قطر‎, 113State of Qatar: 16 05 二零零五 10:57:49:513select
convert(varchar(100卡塔尔, getdate(卡塔尔, 114卡塔尔国: 10:57:49:547select
convert(varchar(100State of Qatar, getdate(State of Qatar, 120卡塔尔国: 贰零零伍-05-16 10:57:49select
convert(varchar(100卡塔尔, getdate(卡塔尔, 121卡塔尔(قطر‎: 二〇〇五-05-16 10:57:49.700select
convert(varchar(100卡塔尔(قطر‎, getdate(卡塔尔(قطر‎, 126State of Qatar: 2006-05-16t10:57:49.827select
convert(varchar(100State of Qatar, getdate(State of Qatar, 130卡塔尔: 18 ???? ?????? 1427
10:57:49:907amselect convert(varchar(100卡塔尔, getdate(卡塔尔, 131State of Qatar: 18/04/1427
10:57:49:920am

方法二

在c#中用惯了datetime.tostring(yyyy-mm-dd卡塔尔(قطر‎,datetime.tostring(mm/dd/yyyy卡塔尔(قطر‎这种日子与字符串的改换方式,在sql
server中没得用,于是乎写了个function,功能跟.net
中的datetime.tostring(formatprovideState of Qatar方法大多,然而只兑现了日期部分,有意思味的相恋的人能够把时间部分补充出来。

create function fn_datetostring(@date datetime, @format varchar(20))

returns varchar(20)

as

begin

declare @result varchar(20)

select @result =
(replace(replace(replace(@format,’yyyy’,’20’+substring(convert(char(8),@date,3),7,2)),’mm’,substring(convert(char(8),@date,3),4,2)),’dd’,substring(convert(char(8),@date,3),1,2)))

return @result

end

使用:

select dbo.fn_datetostring(getdate(),’yyyy-mm-dd’)

网站地图xml地图