Posted By

ramirocalero on 10/16/10


Tagged

sql date tsql padleft ceros REPLICATE


Versions (?)

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


 / Published in: SQL
 

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

  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

Report this snippet  

You need to login to post a comment.