SQL Query for relative time frames

I am trying to create a sql query that lists vulnerabilities between 30 and 60 days ago in order to help automate our Security Program. I have tried using the following but I always get empty results:

WHERE dv.date_published between (now() - interval ‘30 days’) and (now() - interval ‘60 days’)

However, when I use the following , I get results back:

WHERE now() - date_published < INTERVAL ‘60 Days’

I have validated that there are published vulnerabilities between 30 and 60 days ago.

Does anyone have any ideas on how to go about doing this?

Thank you in advance!

@ss_acook_ss_acook We are looking into this for you! I have a ton of SQL Queries but trying to figure out which is closest to this use case.

What is the end state you are trying to get to? Is is just a list of vulnerabilities that meet that criteria?

@ss_acook_ss_acook Try this for me please

WHERE (now() - date_published < INTERVAL ‘60 Days’) AND (now() - date_published > INTERVAL ‘30 Days’)

Sorry, I replied back to the email that I received with your comments but I don’t see my reply on here. That worked! Thanks for your help and sorry for the late reply (that you can see).

1 Like