Convert a Datetime Parameter in a Stored Procedure

  • I am currently using a Start Date and and End Date as my parameters in a stored procedure. When I want to execute my procedure, it's asking me to enter a date and time. How can I convert the startdate and enddate to just a date rather than datetime.

    @startdate datetime

    ,@enddate datetime

  • This bit of code will set the time to be all zeroes.

    DECLARE @midnight DATETIME

    SELECT @midnight = DATEADD(dd,0,DATEDIFF(dd,0,getdate()))

    SELECT @midnight

    Here are some items for date/time you might want to add to your tool box

    https://www.sqlservercentral.com/blogs/lynnpettis/archive/2009/03/25/some-common-date-routines.aspx

    This will return just the date portion, but involves changing DATETIME to VARCHAR - and that is a bit of extra work -- probably too much extra.

    declare @date Char(10)

    set @date = convert(char(10),getdate(),101)

    SELECT @Date

    Another way

    declare @date Char(10)

    SET @date = {fn CURRENT_DATE()}

    SELECT @Date

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply