3 April, 2013
0 Comments
1 category
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/
Tags: T-SQL
Category: Uncategorized