Database fetch with where between two dates
Posted: Mon Jun 26, 2006 6:07 am
Hi,
Am trying to fetch data from the database, for dates between two values. The fields in my database for the dates are under the DATE data type and are working for other operations. I calculate the date after one month from current date, and try to fetch a date value 'DateOfExpiry' between today's date and date after one month, using the following code..
Then i display the rows fetched by the query as a table. When i try this code, it doesnot return any results though there are rows satisfying this condition.
I calculate $today and $next_month by,
When i try to print these values it prints correctly but only the rows are not fetched from the databse. There is no error during fetch and also the field names are correctly displayed in the heading of the table. I am sure, my query statement is not working properly. Where am I wrong ?
Am trying to fetch data from the database, for dates between two values. The fields in my database for the dates are under the DATE data type and are working for other operations. I calculate the date after one month from current date, and try to fetch a date value 'DateOfExpiry' between today's date and date after one month, using the following code..
Code: Select all
$query = "SELECT * FROM customer_info WHERE CustCategory = '$user_categ' AND DateOfExpiry BETWEEN '$today' AND '$next_month'";
$q = mysql_query($query);
if ( ! $q ) { die("Can't Fetch: " .mysql_error()); }I calculate $today and $next_month by,
Code: Select all
$today = date('Y-m-d');
$epoch_today = mktime(0,0,0,date('m'),date('d'),date('y'));
$epoch_next_month = mktime(0,0,0,date('m')+1,date('d'),date(y));
$next_month = strftime('%Y-%m-%d', $epoch_next_month);