将日期(时间)转换为varchar时的默认格式

时间:2017-10-10 13:57:37

标签: sql-server tsql date datetime sql-server-2014

将日期或日期时间转换为varchar时使用的默认格式是什么?什么设置会影响结果?我是否得出了正确的结论,即日期始终转换为YYYY-MM-DDdatetime仅受language的影响?

declare @myDatetime as datetime = dateadd(day,3,getutcdate());
declare @myDate     as date     = @myDatetime;

set dateformat  ymd;        --no difference?
set language    us_english; --affects datetime only?

select
    cast(@myDate     as varchar(max))   --2017-10-13
,   cast(@myDatetime as varchar(max))   --Oct 13 2017  1:47PM
;

set dateformat  dmy;        --no difference?

select
    cast(@myDate     as varchar(max))   --2017-10-13
,   cast(@myDatetime as varchar(max))   --Oct 13 2017  1:47PM
;

set language    Lithuanian; --affects datetime only?

select
    cast(@myDate     as varchar(max))   --2017-10-13
,   cast(@myDatetime as varchar(max))   --spl 13 2017  1:56PM
;

0 个答案:

没有答案