Shery
Shery

Reputation: 1882

BETWEEN Operator mySQL PHP

All,

Not sure why I am getting the error whilst running the following query:

SELECT COUNT(R.id) AS total 
                    FROM request as R 
                    INNER JOIN users AS U ON U.uin = R.engineer_uin 
                    WHERE U.gm = 'BVG1'
                    AND R.date_received BETWEEN DATE_FORMAT(R.date_received,'%d %m %Y')='01 04 2014' AND DATE_FORMAT(NOW(),'%d %m %Y')

R.date_received is in the following format: 2015-06-01 14:38:46 I simply want to get the result between Now() and the previous year. (In the UK, we have financial year between april to next year april.

The error is:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '='01 04 2014' AND DATE_FORMAT(NOW(),'%d %m %Y')
LIMIT 0, 25' at line 5 

Any ideas?

Upvotes: 0

Views: 506

Answers (1)

uri2x
uri2x

Reputation: 3202

The AND clause you're looking for should look as follows:

...
AND R.date_received BETWEEN STR_TO_DATE('01,04,2014','%d,%m,%Y') AND NOW()

Upvotes: 2

Related Questions