mysql select between two dates
Posted: Tue Jan 14, 2014 10:03 am
I am executing the following query which selects the J_RefNum and the J_DateRec from the Jobs table where the date received(J_DateRec) is between $dateFrom and $dateTo.
In this case I have been executing the query using the following dates 13/01/2014 and 14/01/2014.
So $dateFrom = '13/01/2014' and $dateTo = '14/01/2014'
$query = "SELECT J_RefNum, DATE_FORMAT(Jobs.J_DateRec, '%d/%m/%Y') AS J_DateRec FROM Jobs WHERE DATE_FORMAT(Jobs.J_DateRec, '%d/%m/%Y') BETWEEN '$dateFrom' AND '$dateTo'";
The query does return the correct results but it also returns results which are not in between the two dates specified above.
The incorrect dates which it returns are 13/11/2013 and 13/12/2013 which are not in between the two dates 13/01/2014 and 14/01/2014.
Is there anything I am missing in my query.
Any help would be greatly appreciated
Many Thanks
In this case I have been executing the query using the following dates 13/01/2014 and 14/01/2014.
So $dateFrom = '13/01/2014' and $dateTo = '14/01/2014'
$query = "SELECT J_RefNum, DATE_FORMAT(Jobs.J_DateRec, '%d/%m/%Y') AS J_DateRec FROM Jobs WHERE DATE_FORMAT(Jobs.J_DateRec, '%d/%m/%Y') BETWEEN '$dateFrom' AND '$dateTo'";
The query does return the correct results but it also returns results which are not in between the two dates specified above.
The incorrect dates which it returns are 13/11/2013 and 13/12/2013 which are not in between the two dates 13/01/2014 and 14/01/2014.
Is there anything I am missing in my query.
Any help would be greatly appreciated
Many Thanks