从PHP即2016年1月1日至2017年1月1日获取不同年份的两个日期的数据

时间:2017-01-03 04:44:07

标签: php date between

我正在尝试从两个日期获取数据并且它无法正常工作。 我的数据库表格很简单,格式为11/30/2016。 现在我想从2016年11月30日到2017年1月30日获取数据,但它没有显示。

这里是我的代码

.menuitems

2 个答案:

答案 0 :(得分:1)

如果您的created列是日期,那么您必须在2016-01-02检查日期格式,即mysql的YYYY-mm-dd格式。

试试吧。

$querymain="select * from table_name where created BETWEEN '".date("Y-m-d",strtotime($date_from))."' AND '".date("Y-m-d",strtotime($date_to))."'";

答案 1 :(得分:0)

像这样转换你的日期格式

$date_from='2016-11-30'; 
$date_to='2017-01-03';
//using php  you can convert your date like
$date_from = date("Y-m-d",strtotime("11/30/2016"));
$date_to=date("Y-m-d",strtotime("01/03/2017"));
$querymain="select * from table_name where DATE(`created`) BETWEEN '$date_from' AND '$date_to'";

 try this i hope this is working for you.

由于