next day function

  • hi

    i want next day function

    for example. if i enter 12/31/2008 ,it should give me 01/01/2009

  • harri.reddy (7/27/2012)


    hi

    i want next day function

    for example. if i enter 12/31/2008 ,it should give me 01/01/2009

    declare @ThisDay date = '20081231';

    select dateadd(dd, 1, @ThisDay) -- returns the next day

  • harri.reddy (7/27/2012)


    hi

    i want next day function

    for example. if i enter 12/31/2008 ,it should give me 01/01/2009

    Check out DATEADD() in BOL.

    โ€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.โ€ - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Step 1 : adds one day to current datetime

    SELECT GETDATE()+1 AS NextDay

    Step 2 : If only date is required

    SELECT CONVERT(DATE,GETDATE()+1) AS NextDay

    ~ Lokesh Vij


    Guidelines for quicker answers on T-SQL question[/url]
    Guidelines for answers on Performance questions

    Link to my Blog Post --> www.SQLPathy.com[/url]

    Follow me @Twitter

  • Lokesh Vij (7/27/2012)


    Step 1 : adds one day to current datetime

    SELECT GETDATE()+1 AS NextDay

    Step 2 : If only date is required

    SELECT CONVERT(DATE,GETDATE()+1) AS NextDay

    Could just be me, but I'd rather use the dateadd function. It makes explicit what you are doing. Yes, GETDATE() + 1 does imply that you are adding 1 to the current date, but if the column or variable is defined as DATE or DATETIME2 and you try that, you get an error:

    declare @TestDate date = '20120726';

    select @TestDate + 1;

    declare @TestDateTime2 datetime2 = '20120726';

    select @TestDateTime2 + 1;

    Msg 206, Level 16, State 2, Line 2

    Operand type clash: date is incompatible with int

    Msg 206, Level 16, State 2, Line 4

    Operand type clash: date is incompatible with int

  • Yes agreed. This can only be used for datetime.

    I was just trying to show one more way of doing it ๐Ÿ™‚

    ~ Lokesh Vij


    Guidelines for quicker answers on T-SQL question[/url]
    Guidelines for answers on Performance questions

    Link to my Blog Post --> www.SQLPathy.com[/url]

    Follow me @Twitter

  • thx guys

Viewing 7 posts - 1 through 6 (of 6 total)

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