sql - PHP query for a month but gives me last two years
I have a php query
$query = "SELECT * FROM lbs_trace_etrack WHERE lbs_client='$slcustom1' AND MONTH (lbs_date) = MONTH (NOW())";
It pulls or suppose to pull the information from the SQL for the current month, It does this but pulls the information for the previous year as well. How can I change this query to just get the information from the current month current year?
You will want to add this to your WHERE clause as well:
What your query is asking for now is: give me rows for this client with an lbs_date in March. Instead, what you want it is: give me rows for this client with an lbs_date in March of this year.
I don't know which DB engine you are using so you will need to translate the sample (it is also untested but you get the idea) to be relevant but you just need to give it a better comparison date
or if you want to return dates less than the end of the month you could use