Mombu the Microsoft Forum sponsored links

Go Back   Mombu the Microsoft Forum > Microsoft > SQL SERVER (TECHNET) > SQL Minus 7 days from current date
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 1st May 02:09
rfrechette
External User
 
Posts: 1
Default 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
  Reply With Quote


  sponsored links


2 1st May 02:09
hari prasad
External User
 
Posts: 1
Default SQL Minus 7 days from current date


Hello,

SELECT GETDATE()-7

Thanks
Hari
  Reply With Quote
3 1st May 02:09
rfrechette
External User
 
Posts: 1
Default 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
  Reply With Quote
4 1st May 02:09
hugo kornelis
External User
 
Posts: 1
Default SQL Minus 7 days from current date


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 undo***ented GETDATE().

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
  Reply With Quote
5 9th June 01:25
rfrechette
External User
 
Posts: 1
Default SQL Minus 7 days from current date


Thank you Hugo. That was very helpful!

I really appreciate it.

Rachel
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666