Saturday, August 10, 2013

How to get the DDMMYYYYHHMMSSMMM and YYYYMMDDHHMMSSMMM date formats in SQL Server.


Below are the SQL statements by which we can get the required formats:
  • DDMMYYYYHHMMSSMMM format :
               SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 103),'/','') +    
     REPLACE
(CONVERT(VARCHAR(12), GETDATE(), 114) ,':','')
 

  • YYYYMMDDHHMMSSMMM format :
            SELECT REPLACE(REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR, GETDATE(), 
    121),'-',''),':',''),'.',''),' ','')
       

No comments:

Post a Comment