1

Iam newbie to Php and mysql.I have a datetime field in database and upon that datetime field iam generating a report.Here is my query

$date = $year."-".$month;
SELECT *FROM table WHERE request_date LIKE '$date%';

The month and year variables iam taking from input fields in a form.Here iam concatinating those two variables and passing them in the query.But it retruns nothing. The stored value in request_date is of formate 2011-02-28.

Kindly help how to do this.

regards;

2
  • Try to echoing SELECT *FROM table WHERE request_date LIKE '$date%'; what is it echoing? Commented Sep 5, 2013 at 4:22
  • 1
    First write properly your query, create space between * and FROM SELECT * FROM Commented Sep 5, 2013 at 4:25

2 Answers 2

1

put space between * and FROM like this.

$date = $year."-".$month;
SELECT * FROM table WHERE request_date LIKE '$date%';
Sign up to request clarification or add additional context in comments.

Comments

1

If you need to query for Year and month field then you could do:

SELECT * FROM projects 
WHERE YEAR(request_date) = $year AND MONTH(request_date) = $month

Comments

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.