如何获取用户从html表单输入的日期(from-dates & to_dates )
之间的所有数据。当用户输入日期时,例如(1 \ 1 \ 2019)至(30 \ 1 \ 2019)
我要检查MySQL表中日期之间的两个日期
我尝试过:
$from = $_POST['from'];
$end = $_POST['end '];
$sql = "SELECT * FROM table_name WHERE '" . $from . "' between
from_date and to_date and '" . $end . "' between from_date and
to_date
";
from_date和to_date ... col在mysql表中
答案 0 :(得分:2)
在这里,但是您应该contact GCP support directly $from
和$end
来更正格式
"SELECT * FROM table_name WHERE (date_column_name BETWEEN '" . $from . "' AND '" . $end . "') AND (date_column_name2 BETWEEN '" . $from . "' AND '" . $end . "')"
table_name 是要选择的表,而 date_column_name 是日期列。
答案 1 :(得分:1)
尝试一下
$from = $_POST['from'];
$end = $_POST['end '];
$sql = "SELECT * FROM table_name WHERE date_column1 >= '" . $from . "' AND date_column2 <= '" . $end . "' ";
答案 2 :(得分:1)
首先,您需要将输入日期转换为数据库日期格式 yyyy-mm-dd
$from = date('Y-m-d',strtotime($_POST['from']));
$end = date('Y-m-d',strtotime($_POST['end ']));
$sql = "SELECT * FROM table_name WHERE (date_column_name1 BETWEEN '" . $from . "' AND '" . $end . "') AND (date_column_name2 BETWEEN '" . $from . "' AND '" . $end . "')";
OR
$sql = "SELECT * FROM table_name WHERE (from_date_column >='" . $from . "' AND to_date_column <='" . $end . "')";
答案 3 :(得分:0)
请尝试这个
SELECT * FROM table_name
WHERE from_date >='$from' AND to_date <='$end';
或
SELECT * FROM table_name
WHERE from_date BETWEEN '$from' AND '$end' or to_date BETWEEN '$from' AND '$end';