2

so I am trying to return all appointments more than 24 hours ahead of time. I'm positive the error in the code is around the DATE_ADD stuff, so I know that the PHP variables are set correctly. I think I am just thinking about DATE_ADD wrong. I have also tried several variations of brackets with no luck. Just CURDATE() works. Thanks for any help!

$sql =  "   SELECT DISTINCT timeBlocks.date
            FROM timeBlocks
            WHERE timeBlocks.location = '".$appointmentLocation."' AND timeBlocks.school = '".$_SESSION["school"]."' AND timeBlocks.date >= DATE_ADD(curdate(), INTERVAL 1 YEAR)
            ORDER BY timeBlocks.date ASC;"; 
5
  • My experience taught me that using the HEREDOC syntax for multiline strings is better. Commented Apr 29, 2012 at 21:54
  • Thanks! I will read through this now. Commented Apr 29, 2012 at 21:55
  • 1
    gist.github.com/2553439 << example usage with your query. Commented Apr 29, 2012 at 21:58
  • thanks for adding that for me, it really helped me to understand how to write it out correctly! Commented Apr 29, 2012 at 22:07
  • Also. Please don't change the original meaning of the questions, if by any chance a different person would google search your problem, he won't be able to find it if you changed it :) Commented Apr 29, 2012 at 22:09

1 Answer 1

3

Maybe this is too obvious, but it says INTERVAL 1 YEAR instead of 24 hours.

Sign up to request clarification or add additional context in comments.

3 Comments

wow, that totally worked, i feel like a FOOL, thanks so much for finding that...I can't accept the answer for 5 more mins. I realized that there are no appointments for next year yet, so the empty set was causing the syntax error, i think.
Haha we all have moments like this. I once spent 4 hours trying to solve an error that was solved by removing a single quotation mark. Glad to help!
When having moments like these, it usually means you should've hit the bed around 2 hours ago.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.