Date Padding Function
Use a date padding function to return data with a predictable length, mainly used in conjunction with other functions on this site.
About
This is one of our base functions, called by others to return padded values of either two or four characters in length, particularly our DFATEFROMPARTS replacement.
SQL Code
CREATE FUNCTION Dates.DatePad(@PadValue NVARCHAR(100),@PadLen INT) RETURNS NVARCHAR(4) AS BEGINRETURN ISNULL(REPLICATE('0',@PadLen-LEN(@PadValue))+@PadValue,LEFT(@PadValue,@PadLen))ENDGO