﻿<?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 / SQL Server 2005 General Discussion  / date format in stored procedure / 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>Mon, 20 May 2013 16:25:46 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: date format in stored procedure</title><link>http://www.sqlservercentral.com/Forums/Topic933409-149-1.aspx</link><description>Couple of basic things ...Generally you don't want to worry about formatting on the database side.  The db should just be storing the date as a date ... the user interface is where the formatting should take place.  If you have to format on the db side, what you're going to end up with after using the convert function is a varchar, so it won't work to store that in a datetime variable ... the datetime variable will not maintain your format, it will just be whatever the standard datetime format is on your system.  For example, on my system:[code="sql"]declare @date datetimeset @date = CONVERT(varchar(10),getdate(),101)select @date[/code]returns[code="sql"]--2010-06-09 00:00:00.000[/code]while[code="sql"]declare @date varchar(10)set @date = CONVERT(varchar(10),getdate(),101)select @date[/code]returns[code="sql"]--06/09/2010[/code]Again though, you really don't want to store any dates as varchar/char fields ever ... you'll just end up with a mess.And also, this may seem trivial, but anywhere you're doing an insert into a table, you should specify the columns you're inserting into in the correct order.  This will allow you to avoid problems should the column order of the table ever change.</description><pubDate>Wed, 09 Jun 2010 11:31:48 GMT</pubDate><dc:creator>bteraberry</dc:creator></item><item><title>RE: date format in stored procedure</title><link>http://www.sqlservercentral.com/Forums/Topic933409-149-1.aspx</link><description>The Below SQL Command------------ SELECT CONVERT (VARCHAR,GETDATE(),101) [Date]Here GETDATE() is Date field of Table.--Out Put-&amp;gt;mm/dd/yyyy</description><pubDate>Wed, 09 Jun 2010 03:40:38 GMT</pubDate><dc:creator>engr_faruque</dc:creator></item><item><title>RE: date format in stored procedure</title><link>http://www.sqlservercentral.com/Forums/Topic933409-149-1.aspx</link><description>Yes it will be.. but if u be bit more specific on what you need, then v might provide a better solution..</description><pubDate>Mon, 07 Jun 2010 05:09:24 GMT</pubDate><dc:creator>ColdCoffee</dc:creator></item><item><title>RE: date format in stored procedure</title><link>http://www.sqlservercentral.com/Forums/Topic933409-149-1.aspx</link><description>is that date vill be In mm/dd/yyyu format</description><pubDate>Mon, 07 Jun 2010 04:38:44 GMT</pubDate><dc:creator>kavyacb</dc:creator></item><item><title>RE: date format in stored procedure</title><link>http://www.sqlservercentral.com/Forums/Topic933409-149-1.aspx</link><description>Kavya,,  try this:[code="sql"]create procedure USP_InsertStatusText(@Statustext char(150),@RecievedBy varchar(50),@Deliverydate datetime)asBEGINdeclare @date datetimeset @Deliverydate=  convert(varchar,@Deliverydate,1) --as [mm/dd/yy] from TB_StatusEntryinsert into TB_StatusText values(@Statustext,@RecievedBy,@Deliverydate)END[/code]But i tell, you, please store the date field in DateTime and NOT in some other formats.</description><pubDate>Mon, 07 Jun 2010 04:33:16 GMT</pubDate><dc:creator>ColdCoffee</dc:creator></item><item><title>date format in stored procedure</title><link>http://www.sqlservercentral.com/Forums/Topic933409-149-1.aspx</link><description>create procedure USP_InsertStatusText(@Statustext char(150),@RecievedBy varchar(50),@Deliverydate datetime)asBEGINdeclare @date datetimeset @Deliverydate=select @Deliverydate convert(varchar(),getdate(),1)as[mm/dd/yy] from TB_StatusEntryinsert into TB_StatusText values(@Statustext,@RecievedBy,@Deliverydate)ENDi want to convert the Delivery date to mm/dd/yyyy format but am getting error asMsg 156, Level 15, State 1, Procedure USP_InsertStatusText, Line 5Incorrect syntax near the keyword 'select'.</description><pubDate>Mon, 07 Jun 2010 04:27:29 GMT</pubDate><dc:creator>kavyacb</dc:creator></item></channel></rss>