user3261331 user3261331 - 6 months ago 10
MySQL Question

PHP Select data between 2 dates

Sir I try the between operator in mysql php but the result or the output is wrong.


$currentdate = "05-23-2016";

$startdate = "01-01-1001";

$sql="SELECT * FROM `trial` WHERE Schedule BETWEEN '".$startdate."' AND '".$currentdate."' ";
$result =mysql_query($sql) or die (mysql_error());
while($row=mysql_fetch_array($result)){

echo $row['ID']." - ".$row['Msched'].'-'.$row['Dsched'].'-'.$row['Ysched']."" ;

}




Output
1 - 05-18-2016
4 - 04-28-2005
5 - 01-26-2020

Answer

Try :

$sql="SELECT * FROM `trial` WHERE (Schedule BETWEEN '".$startdate."' AND '".$currentdate."') ";
Comments