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:

DECLARE @Date_Value DATETIME
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.

Thanks,

Ethan

Something like this in your query should work.

SELECT *
FROM table
WHERE t_stamp >= DATEADD(day,-7, GETDATE())
2 Likes

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