从两个日期之间的表中选择名称

时间:2016-06-07 09:26:43

标签: php mysql

enter image description here name = Test

start date 5-06-2016
End date 15-06-2016

我想获取名称,如下所示

7-06-2016
9-06-2016

让我解释一下,假设我有一个活动,一个月内发生五天,其开始日期是5-06-2016,结束日期是10-06-2016我想要显示今天的活动日期,e 7 -06-2016 ??

2 个答案:

答案 0 :(得分:1)

您可以使用BETWEEN关键字:

$from_date = "2016-05-06";
$to_date = "2016-05-08";
    "SELECT * FROM logs WHERE date BETWEEN '" . $from_date . "' AND  '" . $to_date . "'
    ORDER by id DESC"

答案 1 :(得分:0)

function check_in_range($start_date, $end_date, $date_from_user)
{
  // Convert to timestamp
      $start_ts = strtotime($start_date);
      $end_ts = strtotime($end_date);
      $user_ts = strtotime($date_from_user);

      // Check that user date is between start & end
      return (($user_ts >= $start_ts) && ($user_ts <= $end_ts));
}
$a = check_in_range("5-06-2016","15-06-2016","01-06-2016");
echo $a;