0

I hav the next query in SQL: SELECT id FROM student WHERE DATE LIKE '%$inputdate' the inputDate is in the next format: 2010.08.03 I also want to change the date of the date, by increasing the day in a week (+7).

I try this:

SELECT id
FROM student
WHERE DATE LIKE '%$inputdate'
     OR DATE Like '%CAST(RIGHT("2012-11-03", 2)AS INT) + 7;

But it gives me SQL syntax error. How can I write it correctly?

1
  • What SQL engine are you dealing with? Commented Nov 7, 2012 at 11:41

1 Answer 1

1

since you are using MySQL, make use of DATE() function

SELECT id
FROM student
WHERE DATE(`DATE`) = DATE(inputdate) OR 
      DATE(`DATE`) = DATE(DATE_ADD(DATE(inputdate),INTERVAL 7 DAY))

SOURCES

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

4 Comments

Thank you. it still not working, because it like the DATA_ADD. How I do that?
do you mean DATE_ADD? what is the data type of DATE in your table? is it date ot stored as varchar?
I got as an input: 2012-11-03, and I want to find the Id's with there date 2010-11-10. But because I also have the hour, it's like the data column, and not equal.
that's why you have to use the function DATE so it will get rid of the time. Let me clarify some things, 1.) what is the format if inputdate? 2.) what is the data type of DATE column, is it DATE or varchar? I also updated the answer.

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.