stored Procedure issues

Hi,
when  I use this stored procedure  it inserts as  MM/DD/YYYY  instead of  DateTime format. Let me know what is the issue on due date..

Thanks


USE [uniflow3]
GO
/****** Object:  StoredProcedure [dbo].[spInsertInstrumentTask]    Script Date: 11/16/2015 6:45:49 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spInsertInstrumentTask]
      @instrumentType varchar(50),
      @taskName varchar(50),
      @taskDescription varchar(50),
      @taskRecurrence varchar(50),
      @taskReminder varchar(50),
      @taskExpiration varchar(50),
      @taskRequired varchar(50),
      @userID varchar(50),
      @eventID bigint,
      @dueDate varchar(20)
AS
SET NOCOUNT ON;
 DECLARE @Date char(8)
set @Date=@dueDate

               
        BEGIN


      INSERT INTO InstrumentTasks(instrumentTypeId,taskName,taskDescription,taskRecurrence,taskReminder,taskExpiration,taskRequired,createdDate,eventId,taskStatus,duedate,lastUpdateEventId)
      VALUES ((select instrumentTypeId from instrumentType where instrumentTYpe = @instrumentType ),@taskName,@taskDescription,@taskRecurrence,@taskReminder,@taskExpiration,@taskRequired,getdate(),@eventID,'Active',CONVERT(datetime,RIGHT(@Date,4)+LEFT(@Date,2)+SUBSTRING(@Date,3,2)),@eventID)

    END
roy_sanuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>@dueDate varchar(20)
>DECLARE @Date char(8)
For starters...
   Why are you handling datetime values in a character field?
   Eight characters is only enough room for a date without a time component.

What is the data type of InstrumentTasks.duedate ?
0
Karthik RamachandranCommented:
Because the INSERT query behaves that way. I understand you expect TIME in the due_date but it isn't now. It must be in DATE format instead of DATETIME format. If it is so, the type of the due_date column needs to be altered to DATETIME and the way of insertion needs to be changed by just populating the Date variable, and remove the statement "set @Date=@dueDate".
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.