gpt4 book ai didi

php - 将过滤器从接受今天更改为同时接受昨天+今天

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

这就是我现在所拥有的:

set_time_limit(120);
$now = (new \DateTime)->format('Y-m-d H:i:s');
$nowYmd = (new \DateTime())->format('Y-m-d');
foreach ($rows as $row) {
$deviceLog = [];
$deviceLog['installation_id'] = $this->parseForNull((int)$row[0]);
$deviceLog['device_id'] = $devicesSerialToId[$row[1]];
$deviceLog['2'] = $this->parseForNull($row[2]);
$deviceLog['3'] = $this->parseForNull($row[3]);
$deviceLog['4'] = $row[4];
$deviceLog['5'] = $this->parseForNull($row[5]);
$deviceLog['6'] = $this->parseForNull($row[6]);
$deviceLog['7'] = $this->parseForNull($row[7]);
$deviceLog['8'] = $this->parseBoolean($row[8]);
$deviceLog['9'] = $this->parseBoolean($row[9]);
$deviceLog['10'] = $this->parseBoolean($row[10]);
$deviceLog['11'] = $this->parseForNull(intval($row[11]));
$deviceLog['12'] = $this->parseForNull($row[12]);
$deviceLog['13'] = $this->parseForNull($row[13]);
$deviceLog['14'] = $this->parseForNull($row[14]);
$deviceLog['15'] = $this->parseForNull($row[15]);
$deviceLog['16'] = $this->parseForNull($row[16]);
$deviceLog['17'] = $this->parseForNull($row[17]);
$deviceLog['18'] = $this->parseBoolean($row[18]);
$deviceLog['19'] = $this->parseBoolean($row[19]);
$deviceLog['20'] = $this->parseForNull($row[20]);
$deviceLog['21'] = $this->parseBoolean($row[21]);
if (!empty($row[22])) {
$date = \DateTime::createFromFormat('d-M-y', $row[22]);
if(!$date || ($date && ($date->format('Y-m-d') != $nowYmd))) {
continue;
}
$deviceLog['last_seen'] = $date->format('Y-m-d');
} else {
continue;
}

因此,目前,如果文件中的行与今天不同,则最后一个“if/else”会使上传的文件不会在数据库中添加行。我想改变这一点,所以今天和昨天被接受,但我不知道如何做。有什么想法吗?

运行 Laravel。

最佳答案

一种方法是为昨天创建一个 DateTime 对象,然后将其与解析的日期进行比较:

$yesterday = new \DateTime('yesterday');

...

$date = \DateTime::createFromFormat('d-M-y', $row[22]);

if(!$date || $date < $yesterday) {

希望这有帮助!

关于php - 将过滤器从接受今天更改为同时接受昨天+今天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42349661/

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