Coding Villa Forum
FAQs
Advertisements

Convert DateTime to Date(MDY) in Sql Server 2008

Iram Online 6/20/2012 4:33:44 PM

Hello Friends!

I am working on a website. On that website i am receiving date from user using Calender Control. I wan t to display that date in Month Day and Year format. Therefore, I want to add convert date query in my store procedure. I don't know the exact syntax for date conversion. So please friends guide me how can i insert convert date query in store procedure. Following is my store procedure


ALTER PROCEDURE [dbo].[Proc_CouponDetails_GetByID2]
          (
                   @CouponID INT
          )
 AS

BEGIN
                SET NOCOUNT ON;

SELECT
                 AD.StoreID,
                AD.TypeID,
                AD.Title,
                AD.Image,
                AD.Description,
                Code,
                AddDate,
                 Exp_Date,
                 (select FName+' '+LName from UserAccounts where ID=AD.UserID) AS UserName,
               AD.PageTitle,
               AD.PageHeading,
               AD.UserID,
               AD.MetaKeywords,
               AD.MetaDescription,
               AD.Slug,
               AMCat.NetworkID ,
               AD.Views
FROM [CouponDetails] AD WITH (NOLOCK)

INNER JOIN [CouponStores] ASCat

ON AD.StoreID = ASCat.StoreID

INNER JOIN [CouponNetworks] AMCat

ON ASCat.NetworkID = AMCat.NetworkID

WHERE CouponID = @CouponID AND AD.Inactive=0


Waiting for your guidance friends


Thanks

Share with Friends

Advertisements

Answer

Inayat Online 6/24/2012 9:59:51 AM

I can tell you how you can convert DateTime.Now to yyyy-mm-dd format such as ISO standard, but you will have figure out your procedure by yourself

Answer

Mehmood Online 6/26/2012 11:42:41 PM

we have many way around. you need to pick the most suitable one according to your need.

I am writing just one but referring many.

SELECT CONVERT(VARCHAR(10),GETDATE(),111)

----------------------------------Other Formats--------------------------------------------------

http://www.sql-server-helper.com/tips/date-formats.aspx

--------------------------------Other Ways------------------------------------------------------

http://blog.sqlauthority.com/2007/06/10/sql-server-retrieve-select-only-date-part-from-datetime-best-practice/

http://stackoverflow.com/questions/1923876/sql-server-convert-intyear-intmonth-intday-to-datetime

http://stackoverflow.com/questions/266924/create-a-date-with-t-sql

http://stackoverflow.com/questions/45535/get-month-and-year-from-a-datetime-in-sql-server-2005


Answer

Mehmood Online 6/27/2012 12:01:18 AM

Dear Inayat,

I really appreciate your effort to teach someone.

But the thing is that we need to provide the sufficient tools and techniques to task achiever.

No one learn from the lap of mother. we were also a part of this learning stage.

Answer

Iram Online 6/29/2012 12:26:05 PM

Mehmood data base fields are in DateTime Type and date is displaying on web form in this "6/14/2012 12:00:00 AM" format. However I want to display it in "June 8, 2012" format. I have changed date format in data list using following method.

<%#Eval("Exp_Date", "{0:MMMM d, yyyy}")%>

But Now I want to change it by Specifying query in StoredProcedure. Can I convert DateTime to above date format using your above mentioned query?
Share with Friends

Post reply

 

Enter This Code
Captcha
 

Subscribe

Email me when people reply


Subscribe to the