现在有一个datetime的列时间
7:51:03
12:51:04
17:36:35
19:19:07
7:50:10用substring()、datepart可以截取7
12
17
19
7现在需要如果是一位的就前面补零(1~9),两位不变(10之后不变)
7 变成 07
12 不变
17 不变
7 变成 07
7:51:03
12:51:04
17:36:35
19:19:07
7:50:10用substring()、datepart可以截取7
12
17
19
7现在需要如果是一位的就前面补零(1~9),两位不变(10之后不变)
7 变成 07
12 不变
17 不变
7 变成 07
from tb
select right('0'+cast(datepart(hour,时间) as varchar),2)
from tb
select CONVERT(char(2),时间,108)
select case when len(datename(hh,时间))=1 then '0'+datename(hh,时间) else datename(hh,时间) end from tb
declare @temptime datetime
set @temptime='7:51:03'
select right('0'+cast(datepart(hour,@temptime) as varchar),2)