﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / T-SQL (SS2K5)  / Converting Getdate() To Varchar / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 19 May 2013 12:51:54 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Converting Getdate() To Varchar</title><link>http://www.sqlservercentral.com/Forums/Topic452328-338-1.aspx</link><description>I believe 14 is what your looking for - [code]select replace(convert(varchar, getdate(),112),'/','') + replace(convert(varchar, getdate(),14),':','') [/code]</description><pubDate>Wed, 06 Feb 2008 10:26:52 GMT</pubDate><dc:creator>Tommy Bollhofer</dc:creator></item><item><title>RE: Converting Getdate() To Varchar</title><link>http://www.sqlservercentral.com/Forums/Topic452328-338-1.aspx</link><description>D'oh!:blush:</description><pubDate>Wed, 06 Feb 2008 10:22:44 GMT</pubDate><dc:creator>ChrisM@Work</dc:creator></item><item><title>RE: Converting Getdate() To Varchar</title><link>http://www.sqlservercentral.com/Forums/Topic452328-338-1.aspx</link><description>Here's a couple of ideas.[code]DECLARE @Now DATETIMESET @Now = GETDATE()SELECT @NowSELECT CAST(datepart(yy, @Now) AS CHAR(4)) + 	RIGHT('0'+LTRIM(cast(datepart(mm, @Now) as VARCHAR(2))), 2) + 	RIGHT('0'+LTRIM(cast(datepart(dd, @Now) as VARCHAR(2))), 2) + 	RIGHT('0'+LTRIM(cast(datepart(hh, @Now) as VARCHAR(2))), 2) + 	RIGHT('0'+LTRIM(cast(datepart(mm, @Now) as VARCHAR(2))), 2) +	RIGHT('0'+LTRIM(cast(datepart(ss, @Now) as VARCHAR(2))), 2) +	RIGHT('00'+LTRIM(cast(datepart(ms, @Now) as VARCHAR(3))), 3)SELECT REPLACE(REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(28), @Now, 121), '-', ''), ' ', ''), ':', ''), '.', '')[/code]</description><pubDate>Wed, 06 Feb 2008 10:21:25 GMT</pubDate><dc:creator>ChrisM@Work</dc:creator></item><item><title>RE: Converting Getdate() To Varchar</title><link>http://www.sqlservercentral.com/Forums/Topic452328-338-1.aspx</link><description>I REALLY appreciate the quick response, exactly what I needed.  Wish I had asked earlier.  :D</description><pubDate>Wed, 06 Feb 2008 10:11:04 GMT</pubDate><dc:creator>RockStar</dc:creator></item><item><title>RE: Converting Getdate() To Varchar</title><link>http://www.sqlservercentral.com/Forums/Topic452328-338-1.aspx</link><description>SELECT LEFT(REPLACE(REPLACE(REPLACE(REPLACE(CONVERT(varchar,GETDATE(), 121),'-',''),':',''),'.',''),' ',''),16)</description><pubDate>Wed, 06 Feb 2008 10:09:22 GMT</pubDate><dc:creator>John Rowan</dc:creator></item><item><title>RE: Converting Getdate() To Varchar</title><link>http://www.sqlservercentral.com/Forums/Topic452328-338-1.aspx</link><description>Try this:select replace(replace(replace(replace(convert(varchar(30), getdate(), 121),'-',''),' ',''),':',''),'.',''):cool:</description><pubDate>Wed, 06 Feb 2008 10:03:59 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: Converting Getdate() To Varchar</title><link>http://www.sqlservercentral.com/Forums/Topic452328-338-1.aspx</link><description>you can just convert the whole thing and strip out the characters.  milliseconds is 3 digits so you'll have to truncate the result from 17 to 16 digits.select substring( replace(replace( replace(replace( convert(varchar,getdate(),121),' ',''),'-',''),':',''),'.',''), 1, 16 )</description><pubDate>Wed, 06 Feb 2008 10:03:50 GMT</pubDate><dc:creator>antonio.collins</dc:creator></item><item><title>Converting Getdate() To Varchar</title><link>http://www.sqlservercentral.com/Forums/Topic452328-338-1.aspx</link><description>Trying to update a timestamp field with getdate().  Field is Varchar (16) and the time needs to be in the following format : YYYYMMDDhhmmssmsExample:  2008020609435709Using the code below to get the second, but in desperate need of how to include the milliseconds in this format.             Select convert(varchar(8),getdate(),112) -- YYYYMMDD							+substring(convert(varchar(8),getdate(),108),1,2) --HH							+substring(convert(varchar(8),getdate(),108),4,2) -- mm							+substring(convert(varchar(8),getdate(),108),7,2) --ssThanks in Advance for your advice!</description><pubDate>Wed, 06 Feb 2008 09:52:54 GMT</pubDate><dc:creator>RockStar</dc:creator></item></channel></rss>