Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Your site has saved me hours of work that I cannot begin to express my satisfaction..."

Geography

Where in the world do Tek-Tips members come from?

rows that are within 30 days of date fieldHelpful Member! 

dkemas (Programmer)
13 Jun 12 7:04
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
Helpful Member!  r937 (TechnicalUser)
13 Jun 12 17:30

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

dkemas (Programmer)
14 Jun 12 4:41
Brilliant that works thanks for the help

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close