MS SQL Queries: Getting Current Date and Using Date Arithmetic to Filter Database Results

Hi all,

I’m trying to create a named query that will only pull data on items that have been introduced after a certain date (this date happens to be whatever the current date is - 7 days). I have been having a lot of trouble getting date functions to work. After a lot of headaches I found that the following function seems to work to acquire the current date:

SET @Date_Value = GETDATE()

The trouble I’m having now is that A: I don’t know the format that this date is in
B: I don’t know how to subtract 7 days from the current date.

If anyone could help me out, I would appreciate it greatly. Ready to smash my head through a wall as I am not very Jython savvy.



Something like this in your query should work.

FROM table
WHERE t_stamp >= DATEADD(day,-7, GETDATE())

You’re a life saver @JordanCClark. Worked like a charm.