+ Reply to Thread
Results 1 to 5 of 5

SQL Minus 7 days from current date

  1. SQL Minus 7 days from current date

    How would I subtract 7 days from the current date?

    I can't seem to get the syntax correct?

    Thank you,

    Rachel

  2. Re: SQL Minus 7 days from current date


    Hello,

    SELECT GETDATE()-7

    Thanks
    Hari

    "RFrechette" wrote in message
    news:575C3EC7-DB74-4634-88C1-21DC0000C48F@microsoft.com...
    > How would I subtract 7 days from the current date?
    >
    > I can't seem to get the syntax correct?
    >
    > Thank you,
    >
    > Rachel




  3. Re: SQL Minus 7 days from current date

    Hi Hari,

    I'm sorry I didn't explain myself very well.

    What I was trying to do was get all files that are 7 days older than today.

    I tried:

    Select oss_tran.acctno, oss_tran.[date]
    from oss_tran
    Where GETDATE()-7

    And I got an error "Error: Line 3: Incorrect syntax near '7'. (State:37000,
    Native Code: AA)"

    I also tried:

    Select oss_tran.acctno, oss_tran.[date]
    from oss_tran
    Where oss_tran.date() - 7

    I got the same error message.

    Any idea of what I'm doing wrong? I'm sure it's something simple.

    Thank you for your help.

    Rachel

    "Hari Prasad" wrote:

    >
    > Hello,
    >
    > SELECT GETDATE()-7
    >
    > Thanks
    > Hari
    >
    > "RFrechette" wrote in message
    > news:575C3EC7-DB74-4634-88C1-21DC0000C48F@microsoft.com...
    > > How would I subtract 7 days from the current date?
    > >
    > > I can't seem to get the syntax correct?
    > >
    > > Thank you,
    > >
    > > Rachel

    >
    >
    >


  4. Re: SQL Minus 7 days from current date

    On Mon, 30 Apr 2007 10:06:00 -0700, RFrechette wrote:

    >Hi Hari,
    >
    >I'm sorry I didn't explain myself very well.
    >
    >What I was trying to do was get all files that are 7 days older than today.


    Hi Rachel,

    SELECT oss_tran,acctno, oss_tran.[date]
    FROM oss_tran
    WHERE oss_tran.[date] >= DATEADD(day, -7, CURRENT_TIMESTAMP);

    * Note that I used DATEADD instead of the non-standard method of
    substracting a number from a datetime, and that I used CURRENT_TIMESTAMP
    instead of the undocumented GETDATE().

    --
    Hugo Kornelis, SQL Server MVP
    My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis

  5. Re: SQL Minus 7 days from current date

    Thank you Hugo. That was very helpful!

    I really appreciate it.

    Rachel

    "Hugo Kornelis" wrote:

    > On Mon, 30 Apr 2007 10:06:00 -0700, RFrechette wrote:
    >
    > >Hi Hari,
    > >
    > >I'm sorry I didn't explain myself very well.
    > >
    > >What I was trying to do was get all files that are 7 days older than today.

    >
    > Hi Rachel,
    >
    > SELECT oss_tran,acctno, oss_tran.[date]
    > FROM oss_tran
    > WHERE oss_tran.[date] >= DATEADD(day, -7, CURRENT_TIMESTAMP);
    >
    > * Note that I used DATEADD instead of the non-standard method of
    > substracting a number from a datetime, and that I used CURRENT_TIMESTAMP
    > instead of the undocumented GETDATE().
    >
    > --
    > Hugo Kornelis, SQL Server MVP
    > My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
    >


+ Reply to Thread