<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; 2008 &#8211; Get Current System Date Time</title>
	<atom:link href="http://blog.sqlauthority.com/2008/08/01/sql-server-2008-get-current-system-date-time/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2008/08/01/sql-server-2008-get-current-system-date-time/</link>
	<description>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:54:09 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Sourabh Sachdeva</title>
		<link>http://blog.sqlauthority.com/2008/08/01/sql-server-2008-get-current-system-date-time/#comment-55747</link>
		<dc:creator>Sourabh Sachdeva</dc:creator>
		<pubDate>Wed, 09 Sep 2009 10:14:26 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=764#comment-55747</guid>
		<description>Hi Pinal,


Good info. But i think u have missed :

select {fn NOW()}</description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>Good info. But i think u have missed :</p>
<p>select {fn NOW()}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kiran</title>
		<link>http://blog.sqlauthority.com/2008/08/01/sql-server-2008-get-current-system-date-time/#comment-54457</link>
		<dc:creator>kiran</dc:creator>
		<pubDate>Wed, 05 Aug 2009 07:45:38 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=764#comment-54457</guid>
		<description>can i get the function in sql server-2000 which gives only the current date excluding time. or any other method to format available functions</description>
		<content:encoded><![CDATA[<p>can i get the function in sql server-2000 which gives only the current date excluding time. or any other method to format available functions</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER - Get Date Time in Any Format - UDF - User Defined Functions Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2008/08/01/sql-server-2008-get-current-system-date-time/#comment-41658</link>
		<dc:creator>SQL SERVER - Get Date Time in Any Format - UDF - User Defined Functions Journey to SQL Authority with Pinal Dave</dc:creator>
		<pubDate>Thu, 14 Aug 2008 01:31:00 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=764#comment-41658</guid>
		<description>[...] 14, 2008 by pinaldave    One of the reader Nanda of SQLAuthority.com has posted very detailed script of converting any date time in desired format. I [...]</description>
		<content:encoded><![CDATA[<p>[...] 14, 2008 by pinaldave    One of the reader Nanda of SQLAuthority.com has posted very detailed script of converting any date time in desired format. I [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nanda</title>
		<link>http://blog.sqlauthority.com/2008/08/01/sql-server-2008-get-current-system-date-time/#comment-41412</link>
		<dc:creator>Nanda</dc:creator>
		<pubDate>Wed, 06 Aug 2008 22:45:03 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=764#comment-41412</guid>
		<description>Sachin,

We have a function which will returns the date &amp; time in required format.

CREATE FUNCTION [dbo].[ufsFormat] 
( 
@Date datetime,
@fORMAT VARCHAR(80) 
) 
RETURNS NVARCHAR(80) 
AS 
BEGIN 
DECLARE @Dateformat INT
DECLARE @ReturnedDate VARCHAR(80)
DECLARE @TwelveHourClock INT
DECLARE @Before INT
DECLARE @pos INT
DECLARE @Escape INT

SELECT @ReturnedDate=&#039;error! unrecognised format &#039;+@format
SELECT @DateFormat=CASE @format
   WHEN &#039;mmm dd yyyy hh:mm AM/PM&#039; THEN 100  
   WHEN &#039;mm/dd/yy&#039; THEN 1 
   WHEN &#039;mm/dd/yyyy&#039; THEN 101 
   WHEN &#039;yy.mm.dd&#039; THEN 2 
   WHEN &#039;dd/mm/yy&#039; THEN 3  
   WHEN &#039;dd.mm.yy&#039; THEN 4  
   WHEN &#039;dd-mm-yy&#039; THEN 5  
   WHEN &#039;dd Mmm yy&#039; THEN 6 
   WHEN &#039;Mmm dd, yy&#039; THEN 7  
   WHEN &#039;hh:mm:ss&#039; THEN 8  
   WHEN &#039;yyyy.mm.dd&#039; THEN 102  
   WHEN &#039;dd/mm/yyyy&#039; THEN 103  
   WHEN &#039;dd.mm.yyyy&#039; THEN 104  
   WHEN &#039;dd-mm-yyyy&#039; THEN 105  
   WHEN &#039;dd Mmm yyyy&#039; THEN 106  
   WHEN &#039;Mmm dd, yyyy&#039; THEN 107  
   WHEN &#039;Mmm dd yyyy hh:mm:ss:ms AM/PM&#039; THEN 9 
   WHEN &#039;Mmm dd yyyy hh:mi:ss:mmm AM/PM&#039; THEN 9 
   WHEN &#039;Mmm dd yy hh:mm:ss:ms AM/PM&#039; THEN 109 
   WHEN &#039;mm-dd-yy&#039; THEN 10 
   WHEN &#039;mm-dd-yyyy&#039; THEN 110  
   WHEN &#039;yy/mm/dd&#039; THEN 11  
   WHEN &#039;yyyy/mm/dd&#039; THEN 111  
   WHEN &#039;yymmdd&#039; THEN 12  
   WHEN &#039;yyyymmdd&#039; THEN 112  
   WHEN &#039;dd Mmm yyyy hh:mm:ss:Ms&#039; THEN 113 
   WHEN &#039;hh:mm:ss:Ms&#039; THEN 14
   WHEN &#039;yyyy-mm-dd hh:mm:ss&#039; THEN 120 
   WHEN &#039;yyyy-mm-dd hh:mm:ss.Ms&#039; THEN 121  
   WHEN &#039;yyyy-mm-ddThh:mm:ss.Ms&#039; THEN 126 
   WHEN &#039;dd Mmm yyyy hh:mm:ss:ms AM/PM&#039; THEN 130 
   WHEN &#039;dd/mm/yy hh:mm:ss:ms AM/PM&#039; THEN 131 
   WHEN &#039;RFC822&#039; THEN -2 
   WHEN &#039;dd Mmm yyyy hh:mm&#039; THEN -4 
   ELSE -1 END
SELECT @ReturnedDate=&#039;error! unrecognised format &#039;                      +@format+CONVERT(VARCHAR(10),@DateFormat)
IF @DateFormat&gt;=0
    SELECT @ReturnedDate=CONVERT(VARCHAR(80),@Date,@DateFormat)
--check for favourite and custom formats that can be done quickly
ELSE IF @DateFormat=-2--then it is RFC822 format
    SELECT @ReturnedDate=LEFT(DATENAME(dw, @Date),3) + &#039;, &#039;                         + STUFF(CONVERT(NVARCHAR,@Date,113),21,4,&#039; GMT&#039;) 
ELSE IF @DateFormat=-4--then it is european day format with minutes
    SELECT @ReturnedDate=CONVERT(CHAR(17),@Date,113) 
ELSE
    BEGIN
    SELECT @Before=LEN(@format)
    SELECT @Format=REPLACE(REPLACE(REPLACE(                    @Format,&#039;AM/PM&#039;,&#039;#&#039;),&#039;AM&#039;,&#039;#&#039;),&#039;PM&#039;,&#039;#&#039;)
    SELECT @TwelveHourClock=CASE WHEN @Before &gt;LEN(@format)                                 THEN 109                                 ELSE 113 END, @ReturnedDate=&#039;&#039;
    WHILE (1=1)--forever
        BEGIN
        SELECT @pos=PATINDEX(&#039;%[yqmidwhs:#]%&#039;,@format+&#039; &#039;)
        IF @pos=0--no more date format strings 
            BEGIN
            SELECT @ReturnedDate=@ReturnedDate+@format
            BREAK
            END
        IF @pos&gt;1--some stuff to pass through first	
            BEGIN
                SELECT @escape=CHARINDEX (&#039;\&#039;,@Format+&#039;\&#039;)                --is it a literal character that is escaped?
                IF @escape&lt;@pos                    BEGIN
                    SET @ReturnedDate=@ReturnedDate+SUBSTRING(@Format,1,@escape-1)                                                   +SUBSTRING(@format,@escape+1,1)
                    SET @format=RTRIM(SUBSTRING(@Format,@Escape+2,80))
                    CONTINUE
                    END
                SET @ReturnedDate=@ReturnedDate+SUBSTRING(@Format,1,@pos-1)
                SET @format=RTRIM(SUBSTRING(@Format,@pos,80))
            END
            SELECT @pos=PATINDEX(&#039;%[^yqmidwhs:#]%&#039;,@format+&#039; &#039;)--get the end
            SELECT @ReturnedDate=@ReturnedDate+--&#039;(&#039;+substring(@Format,1,@pos-1)+&#039;)&#039;+
                CASE SUBSTRING(@Format,1,@pos-1)
                --Mmmths as 1–12 
                WHEN &#039;M&#039; THEN  CONVERT(VARCHAR(2),DATEPART(MONTH,@Date))
                --Mmmths as 01–12 			
                WHEN &#039;Mm&#039; THEN CONVERT(CHAR(2),@Date,101) 
                --Mmmths as Jan–Dec 			
                WHEN &#039;Mmm&#039; THEN CONVERT(CHAR(3),DATENAME(MONTH,@Date))
                --Mmmths as January–December 		
                WHEN &#039;Mmmm&#039; THEN   DATENAME(MONTH,@Date)
                --Mmmths as the first letter of the Mmmth 
                WHEN &#039;Mmmmm&#039; THEN  CONVERT(CHAR(1),DATENAME(MONTH,@Date)) 
                --Days as 1–31 				
                WHEN &#039;D&#039; THEN CONVERT(VARCHAR(2),DATEPART(DAY,@Date))  
                --Days as 01–31 				
                WHEN &#039;Dd&#039; THEN  CONVERT(CHAR(2),@date,103)  
                --Days as Sun–Sat 		
                WHEN &#039;Ddd&#039; THEN  CONVERT(CHAR(3),DATENAME(weekday,@Date))     
                --Days as Sunday–Saturday 		
                WHEN &#039;Dddd&#039; THEN  DATENAME(weekday,@Date)
                --Years as 00–99 				
                WHEN &#039;Yy&#039; THEN    CONVERT(CHAR(2),@Date,12)  
                --Years as 1900–9999 			
                WHEN &#039;Yyyy&#039; THEN  DATENAME(YEAR,@Date)  
                WHEN &#039;hh:mm:ss&#039; THEN SUBSTRING(CONVERT(CHAR(30),@date,@TwelveHourClock),13,8)
                WHEN &#039;hh:mm:ss:ms&#039; THEN SUBSTRING(CONVERT(CHAR(30),@date,@TwelveHourClock),13,12)
                WHEN &#039;h:mm:ss&#039; THEN SUBSTRING(CONVERT(CHAR(30),@date,@TwelveHourClock),13,8)
                --the SQL Server BOL syntax, for compatibility
                WHEN &#039;hh:mi:ss:mmm&#039; THEN SUBSTRING(CONVERT(CHAR(30),@date,@TwelveHourClock),13,12)  
                WHEN &#039;h:mm:ss:ms&#039; THEN SUBSTRING(CONVERT(CHAR(30),@date,@TwelveHourClock),13,12)  
                WHEN &#039;H:m:s&#039; THEN  SUBSTRING(REPLACE(&#039;:&#039;+SUBSTRING(CONVERT(CHAR(30),                                     @Date,@TwelveHourClock),13,8),&#039;:0&#039;,&#039;:&#039;),2,30) 
                WHEN &#039;H:m:s:ms&#039; THEN  SUBSTRING(REPLACE(&#039;:&#039;+SUBSTRING(CONVERT(CHAR(30),                                     @Date,@TwelveHourClock),13,12),&#039;:0&#039;,&#039;:&#039;),2,30) 
                --Hours as 00–23 				
                WHEN &#039;hh&#039; THEN REPLACE(SUBSTRING(CONVERT(CHAR(30),                                     @Date,@TwelveHourClock),13,2),&#039; &#039;,&#039;0&#039;) 
                --Hours as 0–23 				
                WHEN &#039;h&#039; THEN LTRIM(SUBSTRING(CONVERT(CHAR(30),                                     @Date,@TwelveHourClock),13,2))
                --Minutes as 00–59 			
                WHEN &#039;Mi&#039; THEN  DATENAME(minute,@date)
                WHEN &#039;mm&#039; THEN  DATENAME(minute,@date)
                WHEN &#039;m&#039; THEN  CONVERT(VARCHAR(2),DATEPART(minute,@date))
                --Seconds as 0–59 			
                WHEN &#039;ss&#039; THEN  DATENAME(second,@date)
                --Seconds as 0–59 			
                WHEN &#039;S&#039; THEN  CONVERT(VARCHAR(2),DATEPART(second,@date)) 
                --AM/PM 
                WHEN &#039;ms&#039; THEN  DATENAME(millisecond,@date)
                WHEN &#039;mmm&#039; THEN  DATENAME(millisecond,@date)
                WHEN &#039;dy&#039; THEN  DATENAME(dy,@date)
                WHEN &#039;qq&#039; THEN  DATENAME(qq,@date)
                WHEN &#039;ww&#039; THEN  DATENAME(ww,@date)
                WHEN &#039;#&#039; THEN REVERSE(SUBSTRING(REVERSE(CONVERT(CHAR(26),                                    @date,109)),1,2))
                ELSE
                    SUBSTRING(@Format,1,@pos-1)
            END
                SET @format=RTRIM(SUBSTRING(@Format,@pos,80))
        END    END
RETURN @ReturnedDate


Hope the above function will help you.</description>
		<content:encoded><![CDATA[<p>Sachin,</p>
<p>We have a function which will returns the date &amp; time in required format.</p>
<p>CREATE FUNCTION [dbo].[ufsFormat]<br />
(<br />
@Date datetime,<br />
@fORMAT VARCHAR(80)<br />
)<br />
RETURNS NVARCHAR(80)<br />
AS<br />
BEGIN<br />
DECLARE @Dateformat INT<br />
DECLARE @ReturnedDate VARCHAR(80)<br />
DECLARE @TwelveHourClock INT<br />
DECLARE @Before INT<br />
DECLARE @pos INT<br />
DECLARE @Escape INT</p>
<p>SELECT @ReturnedDate=&#8217;error! unrecognised format &#8216;+@format<br />
SELECT @DateFormat=CASE @format<br />
   WHEN &#8216;mmm dd yyyy hh:mm AM/PM&#8217; THEN 100<br />
   WHEN &#8216;mm/dd/yy&#8217; THEN 1<br />
   WHEN &#8216;mm/dd/yyyy&#8217; THEN 101<br />
   WHEN &#8216;yy.mm.dd&#8217; THEN 2<br />
   WHEN &#8216;dd/mm/yy&#8217; THEN 3<br />
   WHEN &#8216;dd.mm.yy&#8217; THEN 4<br />
   WHEN &#8216;dd-mm-yy&#8217; THEN 5<br />
   WHEN &#8216;dd Mmm yy&#8217; THEN 6<br />
   WHEN &#8216;Mmm dd, yy&#8217; THEN 7<br />
   WHEN &#8216;hh:mm:ss&#8217; THEN 8<br />
   WHEN &#8216;yyyy.mm.dd&#8217; THEN 102<br />
   WHEN &#8216;dd/mm/yyyy&#8217; THEN 103<br />
   WHEN &#8216;dd.mm.yyyy&#8217; THEN 104<br />
   WHEN &#8216;dd-mm-yyyy&#8217; THEN 105<br />
   WHEN &#8216;dd Mmm yyyy&#8217; THEN 106<br />
   WHEN &#8216;Mmm dd, yyyy&#8217; THEN 107<br />
   WHEN &#8216;Mmm dd yyyy hh:mm:ss:ms AM/PM&#8217; THEN 9<br />
   WHEN &#8216;Mmm dd yyyy hh:mi:ss:mmm AM/PM&#8217; THEN 9<br />
   WHEN &#8216;Mmm dd yy hh:mm:ss:ms AM/PM&#8217; THEN 109<br />
   WHEN &#8216;mm-dd-yy&#8217; THEN 10<br />
   WHEN &#8216;mm-dd-yyyy&#8217; THEN 110<br />
   WHEN &#8216;yy/mm/dd&#8217; THEN 11<br />
   WHEN &#8216;yyyy/mm/dd&#8217; THEN 111<br />
   WHEN &#8216;yymmdd&#8217; THEN 12<br />
   WHEN &#8216;yyyymmdd&#8217; THEN 112<br />
   WHEN &#8216;dd Mmm yyyy hh:mm:ss:Ms&#8217; THEN 113<br />
   WHEN &#8216;hh:mm:ss:Ms&#8217; THEN 14<br />
   WHEN &#8216;yyyy-mm-dd hh:mm:ss&#8217; THEN 120<br />
   WHEN &#8216;yyyy-mm-dd hh:mm:ss.Ms&#8217; THEN 121<br />
   WHEN &#8216;yyyy-mm-ddThh:mm:ss.Ms&#8217; THEN 126<br />
   WHEN &#8216;dd Mmm yyyy hh:mm:ss:ms AM/PM&#8217; THEN 130<br />
   WHEN &#8216;dd/mm/yy hh:mm:ss:ms AM/PM&#8217; THEN 131<br />
   WHEN &#8216;RFC822&#8242; THEN -2<br />
   WHEN &#8216;dd Mmm yyyy hh:mm&#8217; THEN -4<br />
   ELSE -1 END<br />
SELECT @ReturnedDate=&#8217;error! unrecognised format &#8216;                      +@format+CONVERT(VARCHAR(10),@DateFormat)<br />
IF @DateFormat&gt;=0<br />
    SELECT @ReturnedDate=CONVERT(VARCHAR(80),@Date,@DateFormat)<br />
&#8211;check for favourite and custom formats that can be done quickly<br />
ELSE IF @DateFormat=-2&#8211;then it is RFC822 format<br />
    SELECT @ReturnedDate=LEFT(DATENAME(dw, @Date),3) + &#8216;, &#8216;                         + STUFF(CONVERT(NVARCHAR,@Date,113),21,4,&#8217; GMT&#8217;)<br />
ELSE IF @DateFormat=-4&#8211;then it is european day format with minutes<br />
    SELECT @ReturnedDate=CONVERT(CHAR(17),@Date,113)<br />
ELSE<br />
    BEGIN<br />
    SELECT @Before=LEN(@format)<br />
    SELECT @Format=REPLACE(REPLACE(REPLACE(                    @Format,&#8217;AM/PM&#8217;,'#&#8217;),&#8217;AM&#8217;,'#&#8217;),&#8217;PM&#8217;,'#&#8217;)<br />
    SELECT @TwelveHourClock=CASE WHEN @Before &gt;LEN(@format)                                 THEN 109                                 ELSE 113 END, @ReturnedDate=&#8221;<br />
    WHILE (1=1)&#8211;forever<br />
        BEGIN<br />
        SELECT @pos=PATINDEX(&#8216;%[yqmidwhs:#]%&#8217;,@format+&#8217; &#8216;)<br />
        IF @pos=0&#8211;no more date format strings<br />
            BEGIN<br />
            SELECT @ReturnedDate=@ReturnedDate+@format<br />
            BREAK<br />
            END<br />
        IF @pos&gt;1&#8211;some stuff to pass through first<br />
            BEGIN<br />
                SELECT @escape=CHARINDEX (&#8216;\&#8217;,@Format+&#8217;\')                &#8211;is it a literal character that is escaped?<br />
                IF @escape&lt;@pos                    BEGIN<br />
                    SET @ReturnedDate=@ReturnedDate+SUBSTRING(@Format,1,@escape-1)                                                   +SUBSTRING(@format,@escape+1,1)<br />
                    SET @format=RTRIM(SUBSTRING(@Format,@Escape+2,80))<br />
                    CONTINUE<br />
                    END<br />
                SET @ReturnedDate=@ReturnedDate+SUBSTRING(@Format,1,@pos-1)<br />
                SET @format=RTRIM(SUBSTRING(@Format,@pos,80))<br />
            END<br />
            SELECT @pos=PATINDEX(&#8216;%[^yqmidwhs:#]%&#8217;,@format+&#8217; &#8216;)&#8211;get the end<br />
            SELECT @ReturnedDate=@ReturnedDate+&#8211;&#8217;(&#8216;+substring(@Format,1,@pos-1)+&#8217;)'+<br />
                CASE SUBSTRING(@Format,1,@pos-1)<br />
                &#8211;Mmmths as 1–12<br />
                WHEN &#8216;M&#8217; THEN  CONVERT(VARCHAR(2),DATEPART(MONTH,@Date))<br />
                &#8211;Mmmths as 01–12<br />
                WHEN &#8216;Mm&#8217; THEN CONVERT(CHAR(2),@Date,101)<br />
                &#8211;Mmmths as Jan–Dec<br />
                WHEN &#8216;Mmm&#8217; THEN CONVERT(CHAR(3),DATENAME(MONTH,@Date))<br />
                &#8211;Mmmths as January–December<br />
                WHEN &#8216;Mmmm&#8217; THEN   DATENAME(MONTH,@Date)<br />
                &#8211;Mmmths as the first letter of the Mmmth<br />
                WHEN &#8216;Mmmmm&#8217; THEN  CONVERT(CHAR(1),DATENAME(MONTH,@Date))<br />
                &#8211;Days as 1–31<br />
                WHEN &#8216;D&#8217; THEN CONVERT(VARCHAR(2),DATEPART(DAY,@Date))<br />
                &#8211;Days as 01–31<br />
                WHEN &#8216;Dd&#8217; THEN  CONVERT(CHAR(2),@date,103)<br />
                &#8211;Days as Sun–Sat<br />
                WHEN &#8216;Ddd&#8217; THEN  CONVERT(CHAR(3),DATENAME(weekday,@Date))<br />
                &#8211;Days as Sunday–Saturday<br />
                WHEN &#8216;Dddd&#8217; THEN  DATENAME(weekday,@Date)<br />
                &#8211;Years as 00–99<br />
                WHEN &#8216;Yy&#8217; THEN    CONVERT(CHAR(2),@Date,12)<br />
                &#8211;Years as 1900–9999<br />
                WHEN &#8216;Yyyy&#8217; THEN  DATENAME(YEAR,@Date)<br />
                WHEN &#8216;hh:mm:ss&#8217; THEN SUBSTRING(CONVERT(CHAR(30),@date,@TwelveHourClock),13,8)<br />
                WHEN &#8216;hh:mm:ss:ms&#8217; THEN SUBSTRING(CONVERT(CHAR(30),@date,@TwelveHourClock),13,12)<br />
                WHEN &#8216;h:mm:ss&#8217; THEN SUBSTRING(CONVERT(CHAR(30),@date,@TwelveHourClock),13,8)<br />
                &#8211;the SQL Server BOL syntax, for compatibility<br />
                WHEN &#8216;hh:mi:ss:mmm&#8217; THEN SUBSTRING(CONVERT(CHAR(30),@date,@TwelveHourClock),13,12)<br />
                WHEN &#8216;h:mm:ss:ms&#8217; THEN SUBSTRING(CONVERT(CHAR(30),@date,@TwelveHourClock),13,12)<br />
                WHEN &#8216;H:m:s&#8217; THEN  SUBSTRING(REPLACE(&#8216;:&#8217;+SUBSTRING(CONVERT(CHAR(30),                                     @Date,@TwelveHourClock),13,8),&#8217;:0&#8242;,&#8217;:'),2,30)<br />
                WHEN &#8216;H:m:s:ms&#8217; THEN  SUBSTRING(REPLACE(&#8216;:&#8217;+SUBSTRING(CONVERT(CHAR(30),                                     @Date,@TwelveHourClock),13,12),&#8217;:0&#8242;,&#8217;:'),2,30)<br />
                &#8211;Hours as 00–23<br />
                WHEN &#8216;hh&#8217; THEN REPLACE(SUBSTRING(CONVERT(CHAR(30),                                     @Date,@TwelveHourClock),13,2),&#8217; &#8216;,&#8217;0&#8242;)<br />
                &#8211;Hours as 0–23<br />
                WHEN &#8216;h&#8217; THEN LTRIM(SUBSTRING(CONVERT(CHAR(30),                                     @Date,@TwelveHourClock),13,2))<br />
                &#8211;Minutes as 00–59<br />
                WHEN &#8216;Mi&#8217; THEN  DATENAME(minute,@date)<br />
                WHEN &#8216;mm&#8217; THEN  DATENAME(minute,@date)<br />
                WHEN &#8216;m&#8217; THEN  CONVERT(VARCHAR(2),DATEPART(minute,@date))<br />
                &#8211;Seconds as 0–59<br />
                WHEN &#8217;ss&#8217; THEN  DATENAME(second,@date)<br />
                &#8211;Seconds as 0–59<br />
                WHEN &#8216;S&#8217; THEN  CONVERT(VARCHAR(2),DATEPART(second,@date))<br />
                &#8211;AM/PM<br />
                WHEN &#8216;ms&#8217; THEN  DATENAME(millisecond,@date)<br />
                WHEN &#8216;mmm&#8217; THEN  DATENAME(millisecond,@date)<br />
                WHEN &#8216;dy&#8217; THEN  DATENAME(dy,@date)<br />
                WHEN &#8216;qq&#8217; THEN  DATENAME(qq,@date)<br />
                WHEN &#8216;ww&#8217; THEN  DATENAME(ww,@date)<br />
                WHEN &#8216;#&#8217; THEN REVERSE(SUBSTRING(REVERSE(CONVERT(CHAR(26),                                    @date,109)),1,2))<br />
                ELSE<br />
                    SUBSTRING(@Format,1,@pos-1)<br />
            END<br />
                SET @format=RTRIM(SUBSTRING(@Format,@pos,80))<br />
        END    END<br />
RETURN @ReturnedDate</p>
<p>Hope the above function will help you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: subhro</title>
		<link>http://blog.sqlauthority.com/2008/08/01/sql-server-2008-get-current-system-date-time/#comment-41271</link>
		<dc:creator>subhro</dc:creator>
		<pubDate>Mon, 04 Aug 2008 07:58:07 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=764#comment-41271</guid>
		<description>nice article</description>
		<content:encoded><![CDATA[<p>nice article</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Imran Mohammed</title>
		<link>http://blog.sqlauthority.com/2008/08/01/sql-server-2008-get-current-system-date-time/#comment-41201</link>
		<dc:creator>Imran Mohammed</dc:creator>
		<pubDate>Fri, 01 Aug 2008 22:04:30 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=764#comment-41201</guid>
		<description>@sachin, 

We have something called styles in convert function, you can use them to get the desired output for datetime column,

this will be written like this, 

select (convert (varchar(10), column_name , style_no)


These are the styles that are available in Sql Server, 

Style ID Style Type
 
0 or 100 (*)	mon dd yyyy hh:miAM (or PM)
101	mm/dd/yyyy
102	yy.mm.dd
103	dd/mm/yy
104	dd.mm.yy
105	dd-mm-yy
106	dd mon yy
107	Mon dd, yy
108	hh:mm:ss
9 or 109 (*)	mon dd yyyy hh:mi:ss:mmmAM (or PM)
110	mm-dd-yy
111	yy/mm/dd
112	yymmdd
13 or 113 (*)	dd mon yyyy hh:mm:ss:mmm(24h)
114	hh:mi:ss:mmm(24h)
20 or 120 (*)	yyyy-mm-dd hh:mi:ss(24h)
21 or 121 (*)	yyyy-mm-dd hh:mi:ss.mmm(24h)
126(***)	yyyy-mm-ddThh:mm:ss.mmm(no spaces)
130*	dd mon yyyy hh:mi:ss:mmmAM
131*	dd/mm/yy hh:mi:ss:mmmAM

to know more about this, read &quot;convert&quot; in books online.


Your example :

select convert (varchar(10), getdate(), 101)

result : 08/01/2008

Hope this helps,
Thanks,</description>
		<content:encoded><![CDATA[<p>@sachin, </p>
<p>We have something called styles in convert function, you can use them to get the desired output for datetime column,</p>
<p>this will be written like this, </p>
<p>select (convert (varchar(10), column_name , style_no)</p>
<p>These are the styles that are available in Sql Server, </p>
<p>Style ID Style Type</p>
<p>0 or 100 (*)	mon dd yyyy hh:miAM (or PM)<br />
101	mm/dd/yyyy<br />
102	yy.mm.dd<br />
103	dd/mm/yy<br />
104	dd.mm.yy<br />
105	dd-mm-yy<br />
106	dd mon yy<br />
107	Mon dd, yy<br />
108	hh:mm:ss<br />
9 or 109 (*)	mon dd yyyy hh:mi:ss:mmmAM (or PM)<br />
110	mm-dd-yy<br />
111	yy/mm/dd<br />
112	yymmdd<br />
13 or 113 (*)	dd mon yyyy hh:mm:ss:mmm(24h)<br />
114	hh:mi:ss:mmm(24h)<br />
20 or 120 (*)	yyyy-mm-dd hh:mi:ss(24h)<br />
21 or 121 (*)	yyyy-mm-dd hh:mi:ss.mmm(24h)<br />
126(***)	yyyy-mm-ddThh:mm:ss.mmm(no spaces)<br />
130*	dd mon yyyy hh:mi:ss:mmmAM<br />
131*	dd/mm/yy hh:mi:ss:mmmAM</p>
<p>to know more about this, read &#8220;convert&#8221; in books online.</p>
<p>Your example :</p>
<p>select convert (varchar(10), getdate(), 101)</p>
<p>result : 08/01/2008</p>
<p>Hope this helps,<br />
Thanks,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Flüge Dubai</title>
		<link>http://blog.sqlauthority.com/2008/08/01/sql-server-2008-get-current-system-date-time/#comment-41187</link>
		<dc:creator>Flüge Dubai</dc:creator>
		<pubDate>Fri, 01 Aug 2008 16:15:58 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=764#comment-41187</guid>
		<description>Hej, thanks for the useful post. Sachin, it´s quite simple to change the format of the date. When you implement the script above there you should see the string where to change it.</description>
		<content:encoded><![CDATA[<p>Hej, thanks for the useful post. Sachin, it´s quite simple to change the format of the date. When you implement the script above there you should see the string where to change it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sachin</title>
		<link>http://blog.sqlauthority.com/2008/08/01/sql-server-2008-get-current-system-date-time/#comment-41175</link>
		<dc:creator>Sachin</dc:creator>
		<pubDate>Fri, 01 Aug 2008 11:17:46 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=764#comment-41175</guid>
		<description>Hi

    Can we get the System Date format. For ex. Suppose any body having the system date format is MM/DD/YYYY. Now we need get this Format MM/DD/YYYY. If DD/MM/YYYY means, we need to get the Format DD/MM/YYYY. is it possible?

Regards
Sachin</description>
		<content:encoded><![CDATA[<p>Hi</p>
<p>    Can we get the System Date format. For ex. Suppose any body having the system date format is MM/DD/YYYY. Now we need get this Format MM/DD/YYYY. If DD/MM/YYYY means, we need to get the Format DD/MM/YYYY. is it possible?</p>
<p>Regards<br />
Sachin</p>
]]></content:encoded>
	</item>
</channel>
</rss>
