Agreagar 0 a la izquierda de un numero o fecha. Padleft


/ Published in: SQL
Save to your folder(s)



Copy this code and paste it in your HTML
  1. DECLARE @DATE VARCHAR(8)
  2. SET @DATE = CAST(YEAR(GETDATE()) AS VARCHAR(4))
  3. SET @DATE = @DATE + REPLICATE('0', 2 - DATALENGTH(CAST(MONTH(GETDATE()) AS VARCHAR))) + CAST(MONTH(GETDATE()) AS VARCHAR)
  4. SET @DATE = @DATE + REPLICATE('0', 2 - DATALENGTH(CAST(DAY(GETDATE()) AS VARCHAR))) + CAST(DAY(GETDATE()) AS VARCHAR)
  5. SELECT @DATE

URL: http://www.developerdotstar.com/community/node/319

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.