gpt4 book ai didi

php - 两个日期之间的sql查询

转载 作者:行者123 更新时间:2023-11-29 00:19:09 25 4
gpt4 key购买 nike

form.php

<form  action="dropdown.php" method="POST">
<?php
$month = array();
for ( $i=1; $i<13; $i++ ) {
$month = date('m', mktime(0,0,0,$i,2,2000));
$sel = ( $i == date('n') ? ' selected="selected"' : '');
$options1[] = "<option value=\"{$month}\" {$sel}>{$month}</option>";
}
$options_list1 = join("", $options1);
echo "<select name=\"month\" >{$options_list1}</select>";
for ( $j=1; $j<32; $j++ ) {
$theday = date('d', mktime(0,0,0,0,$j,2000));
$sel = ( $j == date('d') ? ' selected="selected"' : '');
$options2[] = "<option value=\"{$theday}\" {$sel}>{$theday}</option>";
}
$options_list2 = join("\r\n", $options2);
echo "<select name=\"day\" >{$options_list2}</select>";
$arrivalyear = array(2013 => "2013",2014 => "2014");
$selected = date("Y");
echo '<select name="year">';
foreach ($arrivalyear as $i => $v) {
echo "<option value=\"" . $i . "\"";
if ($i == $selected) echo " selected=\"selected\"";
echo ">" . $v . "</option>";
}
echo '</select>';
?>
<span>&nbsp;&nbsp;&nbsp;BETWEEN&nbsp;&nbsp;&nbsp;</span>
<?php
$month = array();
for ( $i=1; $i<13; $i++ ) {
$month = date('m', mktime(0,0,0,$i,2,2000));
$sel = ( $i == date('n') ? ' selected="selected"' : '');
$options1[] = "<option value=\"{$month}\" {$sel}>{$month}</option>";
}
$options_list1 = join("", $options1);
echo "<select name=\"month1\" >{$options_list1}</select>";
for ( $j=1; $j<32; $j++ ) {
$theday = date('d', mktime(0,0,0,0,$j,2000));
$sel = ( $j == date('d') ? ' selected="selected"' : '');
$options2[] = "<option value=\"{$theday}\" {$sel}>{$theday}</option>";
}
$options_list2 = join("\r\n", $options2);
echo "<select name=\"day1\" >{$options_list2}</select>";
$arrivalyear = array(2013 => "2013",2014 => "2014");
$selected = date("Y");
echo '<select name="year1">';
foreach ($arrivalyear as $i => $v) {
echo "<option value=\"" . $i . "\"";
if ($i == $selected) echo " selected=\"selected\"";
echo ">" . $v . "</option>";
}
echo '</select>';
?>
<input type="submit" name="sub" value="Date Filter">

</form>

日期有两个选择选项,如果用户选择 2014-02-102014-02-08 。它将显示这两个日期之间的日期

我知道这个查询,但这并不像我想要的那样工作,因为如果用户选择第一个日期然后选择第二个日期,那么我的查询将不会像我想要的那样执行

select * from mdx
where mdx_timestamp >= '2014-02-10' and mdx_timestamp <= '2014-02-08'

如果有任何解决方案可以找到两个日期之间的日期并且该日期来自数据库

最佳答案

使用 Between 从句

select * from mdx where mdx_timestamp between '2014-02-08' and '2014-02-10'

关于php - 两个日期之间的sql查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21776944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com