Jump to content

[SOLVED] Select data from a date range


nbarone

Recommended Posts

here's what I got:

<?php
function getNumRows($qry){
		if($qry <> NULL){
			$qry = "SELECT * FROM epostcard WHERE ".$qry;
		} else {
			$qry = "SELECT * FROM epostcard";
		}
   		$result = mysql_query($qry);
		$numRows = mysql_num_rows($result);
		unset($qry,$result);
		return $numRows;
	}

$totalPostcards = getNumRows("p_pcSentDate <= '". $dateStart . "' AND p_pcSentDate >= '" . $dateEnd . "'");

 

this returns 0 rows. (incorrect)

 

$totalPostcards = getNumRows("p_pcSentDate BETWEEN '". $dateStart . "' AND '" . $dateEnd . "'");

 

this returns the correct rows, however I need to get the rows that are on dateStart and dateEnd - this does the rows BETWEEN (obv),

You are still doing <= START and >= END. The date can't be both before a start date and after an end date. you want after a start date and before and end date:

$totalPostcards = getNumRows("p_pcSentDate >= '". $dateStart . "' AND p_pcSentDate <= '" . $dateEnd . "'");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.