Home > OS >  I can't show data between two dates
I can't show data between two dates

Time:12-04

As I mentioned in the title, I want to show the data between two dates in the database.

Here is my table:

database

I just want to show the lines between these two dates.

Briefly, the formula will be as follows: departure date ≤ now < arrival date

I've tried many things over the past few days but without success.

If there's an easy way around this, can you also tell me what I should do to show before and after these two dates?Thanks from now..

I tried BETWEEN-INTERVAL

BETWEEN kalkis_tarih - INTERVAL varis_tarih

I tried using if() and i tried many things i found on the internet.

I guess there is a simple solution but I couldn't find it :/

my code:

<?php
        foreach (cok("SELECT * FROM seferler INNER JOIN crew ON crew.crew_id=seferler.kaptan_id INNER JOIN filo ON filo.filo_id=seferler.arac_id INNER JOIN duraklar ON duraklar.id=seferler.kalkis AND seferler.varis ORDER BY kalkis_tarih LIMIT 20") as $key => $sefer): ?>
          <tr>
              <th scope="row text-center">&nbsp;&nbsp;&nbsp;&nbsp;<?= date_format(date_create($sefer['kalkis_tarih']),"d/m/y") ?><br><?= date_format(date_create($sefer['kalkis_tarih']),"h:i") ?> - <?= date_format(date_create($sefer['varis_tarih']),"h:i") ?></th>
              <td><?php foreach(cok("SELECT durak FROM duraklar WHERE id={$sefer['kalkis']}") as $key => $kalkis): ?><?= $kalkis['durak'] ?><?php endforeach ?> | <?= date_format(date_create($sefer['kalkis_tarih']),"d/m - h:i") ?> </td>
              <td><?php foreach(cok("SELECT durak FROM duraklar WHERE id={$sefer['varis']}") as $key => $varis): ?><?= $varis['durak'] ?><?php endforeach ?> | <?= date_format(date_create($sefer['varis_tarih']),"d/m - h:i") ?></td>
              <td><?= $sefer['crew_name'] ?></td>
              <td><?= $sefer['filo_name'] ?></td>
              <td><i ></i></td>
          </tr>

CodePudding user response:

If I understand your question correctly you want those rows from the database where the departure date/time is equal or smaller than the current date/time, and the arrival date/time is bigger than the current date/time.

Basically those rows that are "in transit". This is almost as simple as you wrote it:

departure <= NOW() AND arrival > NOW()

or

kalkis_tarih <= NOW() AND varis_tarih > NOW()
  • Related