Results 1 to 2 of 2

Thread: Datetime SQL Sentence

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2005
    Posts
    59

    Datetime SQL Sentence

    I have the following SP which works ok but not between 00:00 and 23:59:59

    CREATE PROCEDURE dbo.GetFechaVencimiento
    @CantDiasDesde smallint,
    @CantDiasHasta smallint
    AS
    DECLARE @datDesde datetime
    DECLARE @datHasta datetime
    SET NOCOUNT ON;
    SET @datDesde=dateadd(day, @CantDiasDesde, getdate())
    SET @datHasta=dateadd(day, @CantDiasHasta,getdate())
    SELECT fchr,descr,mbox_env,fvenc FROM mer WHERE fvenc>=@datDesde and fvenc<=@datHasta ORDER BY fvenc
    GO

    This SP gets the date at the same time, thus not giving me any chance to get one record. This is why I need to conserve the date but not the time.

    Hope this is clear to help me to figure this out,

    Marcelo.

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Datetime SQL Sentence

    Something like this will remove time from the date...

    Code:
    DECLARE @datDesde datetime
    DECLARE @datHasta datetime
    DECLARE @DateOnly datetime
    SET NOCOUNT ON;
    Set @DateOnly=Cast(Convert(Char(10),GetDate(),101) as datetime)
    SET @datDesde=dateadd(day, @CantDiasDesde, @DateOnly)
    SET @datHasta=dateadd(day, @CantDiasHasta,@DateOnly)
    SELECT fchr,descr,mbox_env,fvenc FROM mer WHERE fvenc>=@datDesde and fvenc<=@datHasta ORDER BY fvenc

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width