Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rows that are within 30 days of date field 1

Status
Not open for further replies.

dkemas

Programmer
Mar 22, 2012
70
GB
A table contains a date field of the format yyyy-mm-dd, I want to grab rows where today is 30 days before that date.

The final script will be run every day as a cron job so needs to pull dates that are exactly 30 days away, but as that will not return any rows today, I have been trying to create a script initially that will pull rows within 30 days.

I have tried alsorts of ways but can't get it to pull the rows.

Here is what I am trying

Code:
SELECT staff_name, date_due_to_complete FROM mytable WHERE DATEDIFF(NOW(), date_due_to_complete) <= 30 )

So for example today is 13th June, I have a row where date_due_to_complete is 20th June so it would fall within 30 days, but the query above returns 0 rows.

Thanks for any help
 
Code:
SELECT staff_name
     , date_due_to_complete 
  FROM mytable 
 WHERE date_due_to_complete <= CURRENT_DATE + INTERVAL 30 DAY

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Brilliant that works thanks for the help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top