[英]How to filter Date Month And Year in php from a timestamp field from database
i have a cms in php where i make booking records in my db i want to make a report about a bookings for a specific month/year in order for that i need to filter those record according to my need when i put a month all the records are displayed in my table of that month this can also be applied for the year record... 我在php中有一个cms,我在我的数据库中做预订记录,我想针对某个特定月份/年份进行预订报告,以便当我把一个月所有记录显示在我当月的表格中,这也可以用于年份记录...
<script>
function myFunction() {
console.log("hello");
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("myinput");
filter = input.options[input.selectedIndex].text;
date = new Date(filter);
month = date.getMonth().toString();
filter = month;
//console.log(filter);
table = document.getElementById("mytable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[6];
if (td) {
// txtValue = td.textContent || td.innerText;
txtValue = new Date(td.innerText).getMonth().toString();
console.log(txtValue);
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
Filter Date:
<div class="form-group">
<label for="">Month</label>
<select name="date" id="myinput">
<?php
$query = "SELECT * FROM package_booking WHERE date";
$select_date = mysqli_query($connection, $query);
confirmQuery($select_date);
while ($row = mysqli_fetch_assoc($select_date)) {
$pb_id = $row['pb_id'];
$date = $row['date'];
$mon = date('m', strtotime($date));
echo "<option value=''>{$date}</option>";
}
?>
</select>
</div>
this code i made is in JS but now i need to know the php part that can filter records in my DB in order to get a record for a month. 我编写的这段代码是用JS编写的,但现在我需要知道可以过滤数据库中记录的php部分,以便获得一个月的记录。
Your code isn't formatted properly, but You might want to try something like: 您的代码格式不正确,但是您可能需要尝试执行以下操作:
SELECT * FROM `your_db_name` WHERE Year(the_date_field_in_your_db) = 'the_year_you_need' AND MONTH(the_date_field_in_your_db)= 'date_numerical_value';
Dates are usually stored in number (1 for January, 2 for February, etc). 日期通常以数字存储(1月1日,2月2日等)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.