0 Comments

If you want to left pad a string in T-SQL in Microsoft SQL Server 2012, you can use the format function:

To get the current hour padded with, zeros use:

declare @CurrentDateTime datetime = '2013-04-03 05:06:17'
select format(datepart(hh, @CurrentDateTime), '00')

-- Result: 05

For more information, including (SQL 2005, and 2008 options):

http://www.tech-recipes.com/rx/30469/sql-server-how-to-left-pad-a-number-with-zeros/

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts