2017-02-20 4 views
0

Das ist, was ich jetzt haben:Filter ändern von beiden Gestern akzeptieren TODAY akzeptieren + Heute

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; 
} 

Also, zur Zeit, das letzte „if/else“ macht die hochgeladene Datei nicht Zeile in DB hinzufügen, wenn Die Zeile in der Datei ist nicht derselbe Tag wie heute. Ich möchte das ändern, heute und gestern ist akzeptiert, aber ich habe keine Ahnung wie. Irgendwelche Ideen?

Laufende Laravel.

Antwort

1

Eine Möglichkeit, dies zu tun, wäre ein DateTime Objekt für gestern zu erstellen und dann das Datum auf den analysierten vergleichen:

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

... 

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

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

hoffte, das hilft!

+0

Funktioniert wie ein Charme. Ich danke dir sehr. Nicht sicher, warum ich so verloren war, aber. :) – Stoff

+0

@RiggsFolly Ich würde meine Antwort nicht als Tutorial einstufen ... –

Verwandte Themen