iso.obj.php
$from = null;
$too = null;
if (isset($_POST['search'])) {
if ($from = null) {
$from = date("Y-m-d");
} else {
$from = $_POST['FromDateTime'];
}
if ($too = null) {
$too = date('Y-m-d', strtotime("+30 days")) . " 23:59:59";
} else {
$too = $_POST['ToDateTime']." 23:59:59";
}
}
$sql ="//statement here with
WHERE capDateTime >='{$from}' AND capDateTime <='{$too}'";
代码工作正常但是当我请求页面并且它返回一个空表时我遇到了问题。但如果我手动选择日期和时间,它将根据日期和时间显示。
我的问题是:如果没有设置,我如何设置当前日期?如果设置为$ _POST,我该怎么设置?
答案 0 :(得分:2)
$from = date("Y-m-d");
$too = date('Y-m-d', strtotime("+30 days")) . " 23:59:59";
if (isset($_POST['search'])) {
if (!empty($_POST['FromDateTime'])) {
$from = $_POST['FromDateTime'];
}
if (!empty($_POST['ToDateTime'])) {
$from = $_POST['ToDateTime']." 23:59:59";
}
}