开发者

produce leading 0 in the minutes field

开发者 https://www.devze.com 2023-01-06 05:21 出处:网络
This snippe开发者_开发百科t: select Datename(hh,DATEADD(HH, -5, [time])) + \':\' + Datename(mi,[time])....

This snippe开发者_开发百科t:

select Datename(hh,DATEADD(HH, -5, [time])) + ':' + Datename(mi,[time])....

will produce:

11:4

But i need the leading '0' in front of the '4'.


You can pad the minutes with leading zeros, and then take the right two characters:

SELECT Datename(hh,DATEADD(HH, -5, [time])) + ':' + 
    right('00' + Datename(mi,[time]), 2)


declare @hoje datetime = getdate() select @hoje,format(@hoje,'HH') +':' + format(@hoje,'mm')

0

精彩评论

暂无评论...
验证码 换一张
取 消