jeudi 6 mars 2014

Pull Dates From SQL Database


Vote count:

0




I am having trouble pull dates within a user selected range from a MSSQL database. I assume the problem has something to do with the comparison in my select statement because I think sql gives dates a special format, so I am having trouble comparing my string sql variable against the date variables in the sql database. First I will show you my code php code and then a screenshot of a date. Thank you for your help and assistance it is appreciated.


I am printing out the array that should be populated with the dates so that I see if it's working. Also dates are pulled from the user as mm/dd/yyyy. My echo statement prints out 31 when I search between the dates of 02/03/2014 and 02/18/2014.



//testing ranges
$testArray = array();
$startDate = $_POST['datepicker'];
$endDate = $_POST['datepicker2'];
$startDate = explode("/", $startDate);
$endDate = explode("/",$endDate);
$startDate = $startDate[2]."-".$startDate[0]."-".$startDate[1]." "."00:00:00.000";
$endDate = $endDate[2]."-".$endDate[0]."-".$endDate[1]." "."00:00:00.000";

$ifTest = "SELECT COUNT(*) AS testD FROM dbo.Response WHERE dbo.Response.response_date BETWEEN
'".$startDate."' AND '".$endDate."'";
$db -> query($ifTest);
$x = $db->fetch();
$testArray[] = array('testDate' => $x['testD']);
foreach($testArray as $such)
{
echo $such['testDate'];
}
//end ranges


SQL database



asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire