Add One Day to a Date

  • Hello Everyone

    Is anyone snowed in like me?

    I am trying to add a single day to a date data type value

    DECLARE @TodaysDate Date

    DECLARE @TomorrowsDate Date

    SET @TodaysDate = 2010-2-14

    SET @TomorrowsDate = (@TodaysDate + 1)

    I am receiving this error:

    Operand type clash: date is incompatible with int

    I cannot find, or do not understand what the BOL states about this conversion.

    Can someone point me in the correct direction?

    Thanks

    Andrew SQLDBA

  • Try this

    DECLARE @TodaysDate Date

    DECLARE @TomorrowsDate Date

    SET @TodaysDate = '20100214'

    SET @TomorrowsDate = DATEADD(dd,1,@TodaysDate)

    Regards,

    Willem
    http://wschampheleer.wordpress.com[/url]

  • AndrewSQLDBA (2/10/2010)


    Hello Everyone

    Is anyone snowed in like me?

    I am trying to add a single day to a date data type value

    DECLARE @TodaysDate Date

    DECLARE @TomorrowsDate Date

    SET @TodaysDate = 2010-2-14

    SET @TomorrowsDate = (@TodaysDate + 1)

    I am receiving this error:

    Operand type clash: date is incompatible with int

    I cannot find, or do not understand what the BOL states about this conversion.

    Can someone point me in the correct direction?

    Thanks

    Andrew SQLDBA

    try: set @TomorrowsDate = dateadd(dd, 1, @TodaysDate)

    Edit: Also make this change: SET @TodaysDate = '2010-2-14'

  • Whoooops!

    I forget the quotes around the date. But you get the jest of it. I know the date is supposed to have quotes.

    Thanks Everyone. I will try your suggestions

    Is that listed in the BOL? Or did I just not see it in the Date & Time data type section?

    Andrew SQLDBA

  • dateadd in BOL

    and a great post about dates in T-SQL

    Regards,

    Willem
    http://wschampheleer.wordpress.com[/url]

  • Thanks, I hope this can help someone else also.

    I will go back and read it again. Maybe i looked right over it

    Andrew SQLDBA

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

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