Sql date substract question

Hi everyone,

I need to substract one day from de system date(yesterday).

example:

execute spGetCustomers GetDate()-1,null,null --system date less one day(yesterday)

Can someone tell what is the SQL sintax to do that.

Thank's



Answer this question

Sql date substract question

  • Vincent Randal

    Use DateAdd() function.
  • snakey_tv

    You will need to store the value in a variable as you can't use expressions in stored procedure calls.

    so

    declare @yesterday datetime

    set @yesterday = getdate()-1 --or set @yesterday = dateadd(d,-1,getdate())

    exec sp_MySP @yesterday,.....

    Remember that getdate() includes the time so adding -1 will result in a data with the same time as now but a day ago. It won't be the start of yesterday.



  • GUYO

    Hey,

    Your example itself is right !! you can use getdate().

    anyways, this is the syntax.

    dateadd(dd, -1, getdate())

    Amarnath


  • Sql date substract question