- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在数据库中有一些条目,我想按它们发生的那一周进行分组。我想要做的是确定条目发生在一年中的哪一周,然后显示该周以及该周的星期一和星期五。本页http://princeave.com/bo/test.php显示我得到的输出。请注意,星期一和星期五对于 2017 年发生的事件是正确的,但对于 2018 年发生的事件则不正确。代码如下。我错过了什么?
<?php //Gets list of weeks that I can bill
try {
$stmt2 = $db->prepare("SELECT DISTINCT YEAR(transaction_date) AS YR, WEEK(bo_hourly_charges.transaction_date) as wk FROM bo_hourly_charges WHERE billed_by='AfterCare' ORDER BY transaction_date DESC");
$stmt2->execute();
// set the resulting array to associative
$result2 = $stmt2->setFetchMode(PDO::FETCH_ASSOC);
$count = $stmt2->rowCount();
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
?>
<div align='center'>
<br>
<?php
foreach (($stmt2) as $row) {
$fix = $row['YR']."W".$row['wk'];
$monday=date('M d',strtotime($fix));
$friday=date('M d',strtotime($fix.'5'));
print $fix." ".$row['wk']." ".$monday."-".$friday."<br>";
++$i;
}
?>
最佳答案
有趣的问题,我不知道 PHP 允许这种格式。我不相信这是记录在案的行为。因此,依赖它可能并不明智。
Running your code with the full range of weeks in 2017快速显示问题与 2018 年无关:
<?php
$dates = [];
for ($i = 1; $i <= 52; $i++) {
$dates[] = ['YR' => 2017, 'wk' => $i];
}
foreach ($dates as $row) {
$fix = $row['YR']."W".$row['wk'];
$monday=date('M d',strtotime($fix));
$friday=date('M d',strtotime($fix.'5'));
print $fix." ".$row['wk']." ".$monday."-".$friday."\n";
++$i;
}
产量:
(...)
2017W5 5 Dec 31-Dec 31
2017W6 6 Dec 31-Dec 31
2017W7 7 Dec 31-Dec 31
2017W8 8 Dec 31-Dec 31
2017W9 9 Dec 31-Dec 31
2017W10 10 Mar 06-Mar 10
2017W11 11 Mar 13-Mar 17
2017W12 12 Mar 20-Mar 24
2017W13 13 Mar 27-Mar 31
2017W14 14 Apr 03-Apr 07
(...)
相反,2017 年的前九周似乎也有类似的问题。从第 10 周开始,问题似乎已解决。
第 1 至 9 周与第 10 周及以上的差异与格式密切相关。
Padding the weeks with a zero似乎解决了问题:
<?php
$dates = [];
for ($i = 1; $i <= 52; $i++) {
$dates[] = ['YR' => 2017, 'wk' => $i];
}
foreach ($dates as $row) {
$fix = $row['YR']."W".str_pad($row['wk'], 2, '0', STR_PAD_LEFT);
$monday=date('M d',strtotime($fix));
$friday=date('M d',strtotime($fix.'5'));
print $fix." ".$row['wk']." ".$monday."-".$friday."\n";
++$i;
}
然而,更明智的选择是使用更常见的日期格式。
关于php - 确定星期一和星期五代码停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48651840/
我正在尝试执行不是很复杂的图像分析,以尝试找到不同的形状并计算它们的一些参数,如面积和周长(以像素为单位),我正在尝试在 Haskell 中执行此操作(我想这样做是为了尝试并使用函数式编程语言)。 第
查看 main 函数,我们可以看到我已将“星期一”硬编码到我的 setDay 公共(public)函数中。使用 c 字符串很容易从用户那里获取星期几(就像我在 setDay 中所做的那样),但是我如何
我正在寻找两个做两件事: 检查一周是否过去(基于星期几) 检查一天是否过去(基于日期) 我不确定解决这个问题的最佳方法是什么,因为比较两个 NSDates(一个在 2009 年 1 月 1 日 21:
伙计们,我想创建一个 13 日即将到来的 13 个星期五的列表我该怎么做? 我尝试了一年: public static void getFridayThirteen() { for (in
我想知道这个日期格式是什么 Friday, December 18th 也是这个标准日期格式,或者我必须努力工作才能得到这个。 谢谢。 最佳答案 我认为th 不可能通过格式化程序实现。虽然你可以这
我正在使用 UILocalNotification 进行报警。我有一个基于工作日(星期日、星期一、星期二、星期三、星期四、星期五、星期六)重复的自定义选项。这么多应用程序都做了这个过程。我尽力了。但我
下面的函数返回图表数据 上述函数返回的输出格式如下 [Object { date=Date, value=112, volume=1469}, Object { date=Date, value
我是一名优秀的程序员,十分优秀!