下面的PHP代码在当前日期运行良好,可以从MySQL中获取数据,用于特定id的出勤。我需要它为现在的一周和一个月拿来。我在谷歌上搜索了很多,但无法解决。小小的帮助是非常感谢的。
如果有可能使用JavaScript,请告诉我。
// SELECT Time Zone
date_default_timezone_set("Europe/Belfast");
// SELECT Date With Default Time i.e "00:00:00"
$date= date("y-m-d 00:00:00");
$mysqli=mysqli_connect('localhost','Uid','PASS','DB');
//Passed From Ajax
$Fetch_date = $_POST['ID'];
// Example Date is 2015-06-18 00:00:00 And id is 12345
$query ="SELECT * FROM attendance WHERE RegID='$Fetch_date' And Date='$date' ";
$result = mysqli_query($mysqli,$query)or die(mysqli_error());
$num_row = mysqli_num_rows($result);
while($row=mysqli_fetch_array($result))
{
//Echo result hear Working Fine
}发布于 2015-06-08 08:11:06
本月:
$date1 = date('Y-m-01 00:00:00');
$date2 = date('Y-m-d 23:59:59', strtotime('last day of this month'));
$sql = "select * from attendance where RegID='$Fetch_date' and Date > '$date1' and Date < '$date2' ";本周:
$date1 = date('Y-m-d 00:00:00', strtotime('monday this week'));
$date2 = date('Y-m-d 23:59:59', strtotime('sunday this week'));
$sql = "select * from attendance where RegID='$Fetch_date' and Date > '$date1' and Date < '$date2' ";P.S.:这个问题与javascript无关。
发布于 2015-06-08 08:23:04
您可以使用mysql-日期-函数
$query ="SELECT * FROM attendance
WHERE RegID = '$Fetch_date'
AND YEAR(Date) = YEAR(NOW())
AND MONTH(Date) = MONTH(NOW())
AND WEEKOFYEAR(Date) = WEEKOFYEAR(NOW())";在Javascript中,您可以使用类似的方式进行测试,使用getFullYear和getMonth。返回年度周的函数不可用,但可以使用基于Math.floor(MillisecondsOfTheDate/MillisecondsOfAWeek)的比较
https://stackoverflow.com/questions/30703872
复制相似问题