Dateadd function error

  • Hi There,

    I am trying to use DATEADD function as follows:

    SELECT DATEADD(MINUTE,(CONVERT(DATETIME,CONVERT(VARCHAR,20100501),121)),'02/05/2010')

    I am getting error as:

    "Argument data type datetime is invalid for argument 2 of dateadd function."

    Suggest me some way.

    Thank you.

  • Check the format for DATEADD in BOL - you aren't using it correctly.

    BrainDonor

  • Not sure what you are trying to achieve here. I also suggest you check BOL to understand the syntax, but here's two additional comments:

    1. why write convert(varchar,20100201) and not '20100201'?

    2. you specify format 121 to do the conversion from a string to a datetime but this format is not consistent with the format of your string - again, check BOL. But you also may find this article useful.

    Regards,

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

  • You have made a mistake in the parameters of DateAdd function.

    Second parameter is the number of minutes you need to add to the date given as the third parameter. So, try this:

    SELECT DATEADD(MINUTE,10,'02/05/2010')

    --Divya

Viewing 4 posts - 1 through 3 (of 3 total)

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