简体   繁体   中英

How to Display Date Range codeigniter

I want to display date

SQL date

in page home_model :

public function get_filmkategori($gambar = FALSE)
{

        if ($gambar === FALSE)
    {
        $query = $this->db->get('film');
        return $query->result_array();
    }
        $this->db->select('*');
        $this->db->from('film');
        $this->db->join('kategori', 'kategori.kd_kategori = 
        film.kd_kategori','left');
        $this->db->join('jadwal', 'film.kd_film = jadwal.kd_film','left');
        $query = $this->db->get();
        return $query->row_array();
}

in page view :

 <?php
   $query = $this->db->query("select *  FROM jadwal");

   foreach ($query->result() as $row) :?>

   <strong><?php echo $row->tgl_tayang;?></strong>
    <span>Nov</span>
   </div>
  <div class="col s1">
  <strong><?php echo $row->tgl_berakhir;?></strong>
   <span>Nov</span>
   </div>
  <?php endforeach;?>

I want to display array range tgl_tayang until tgl_berakhir

example php array using loop statement without a database

You can use DatePeriod

For simple example :

$begin = new Datetime('2017-02-01'); // <-- start date
$end = new Datetime('2017-02-10'); // <-- end date

$daterange = new Dateperiod($begin, new dateInterval('P1D'), $end);

foreach ($daterange as $date) {
    echo $date->format("Y-m-d"). "<br>";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM