将日期或日期时间转换为varchar时使用的默认格式是什么?什么设置会影响结果?我是否得出了正确的结论,即日期始终转换为YYYY-MM-DD
而datetime
仅受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
;