最近跟日期相关的内容杠上了,为方便自己后期查阅,特地做笔记。
DECLARE @chanenddate datetime----截止日期转成当天的年月日+尾巴
DECLARE @chanbengindate datetime----开始日期转成当天的年月日+0000000
截取日期的 年月日,字符串类型
convert(varchar, cast(@begindate as date), 23)
截取日期的 时分秒,字符串类型
SELECT CONVERT(VARCHAR,@enddate,8)
截取日期开始时间的年月日,拼接上结束时间的时分秒,在转成日期型
select @chanenddate=(select cast(convert(varchar, cast(@begindate as date), 23)+' '+(SELECT CONVERT(VARCHAR,@enddate,8)) as datetime))
截取开始时间的年月日,给拼接上指定的时分秒 ' 00:00:00:000'
select @chanbengindate=(select cast(convert(varchar, cast(@begindate as date), 23)+' 00:00:00:000' as datetime))