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')
精彩评论