I am working with a DB that I cannot alter. I was wondering if there was a way to achieve what I am attempting in a mysql_query or if I have to format through PHP. Long story short, I have to pull be two fields from the DB, entry month and entry year. I need to pull all instances, for example, between July last year and June this year. I was attempting to do this with concat_ws and date_format but it is not working correctly. This is my current query.
[code=php]$select = mysql_query(“SELECT *, CONCAT_WS(‘-‘,entry_month,entry_year) AS condate FROM kpi
WHERE DATE_FORMAT(condate,’%m-%Y’) >= ‘$start_time’ AND
DATE_FORMAT(condate,’%m-%Y’) <= ‘$end_time'”);
This however is not working correctly because it is not finding condate as a useable variable. Is this possible in the query itself?
I’ve also tried this but it isn’t working as no results are returned.
[code=php]$select = mysql_query(“SELECT * FROM kpi
WHERE DATE_FORMAT(CONCAT_WS(‘-‘,entry_month,entry_year),’%m-%Y’) >= ‘$start_time’ AND
DATE_FORMAT(CONCAT_WS(‘-‘,entry_month,entry_year),’%m-%Y’) <= ‘$end_time'”);