开发者

produce leading 0 in the minutes field

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜