[英]How to make date range work in my query
How to make date range work in my query, if I include AND sales_date BETWEEN '$from' AND '$to'
it doesn't show anything. 如何使日期范围在我的查询中起作用,如果我在
AND sales_date BETWEEN '$from' AND '$to'
加上AND sales_date BETWEEN '$from' AND '$to'
,则不会显示任何内容。
This is my from, to code 这是我的代码
From (<?php echo $from; ?>) To (<?php echo $to; ?>)
This is my query. 这是我的查询。 I want to make date range work in my query thanks
我想在查询中使用日期范围,谢谢
<?php
$iq=mysqli_query($conn,"select * from inventory left join product on product.productid=inventory.productid order by inventory_date desc ");
while($iqrow=mysqli_fetch_array($iq)){
?>
<tr>
<td class="hidden"></td>
<td><?php echo date('M d, Y h:i A',strtotime($iqrow['inventory_date'])); ?></td>
<td>
<?php
$u=mysqli_query($conn,"select * from `user` left join customer on customer.userid=user.userid left join supplier on supplier.userid=user.userid where user.userid='".$iqrow['userid']."'");
$urow=mysqli_fetch_array($u);
if($urow['access']==1){
echo "Admin";
}
elseif($urow['access']==2){
echo $urow['customer_name'];
}
else{
echo $urow['company_name'];
}
?>
</td>
<td align="right"><?php echo $iqrow['action']; ?></td>
<td align="right"><?php echo $iqrow['product_name']; ?></td>
<td align="right"><?php echo $iqrow['quantity']; ?></td>
</tr>
<?php
} }
?>
您可以在查询中使用BETWEEN
select * from inventory left join product on product.productid=inventory.productid where inventory_date BETWEEN CAST('$startdate' AS DATE) AND CAST('$enddate' AS DATE) order by inventory_date desc
Check your inventory_date
field datatype is date or not and also it contain date or not. 检查您的
inventory_date
字段数据类型是否为日期,并且是否包含日期。
Check $startdate
and $enddate
is contain date with yyyy-mm-dd
format. 检查
$startdate
和$enddate
是否包含yyyy-mm-dd
格式的日期。
$sql = "select * from inventory
left join product on product.productid=inventory.productid
where
date(inventory_date) BETWEEN ".$startdate." AND ".$enddate." order by inventory_date desc";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.