Codeigniter: how to get data between today and last 15 days from database

前端 未结 5 400
谎友^
谎友^ 2021-01-13 00:55

my database table looks like below

| id | user_name | address | contact | date | |----|-----------|---------|---------|----------| | 1 | john | NY

5条回答
  •  余生分开走
    2021-01-13 01:02

    You can use the following query to get last 15 days data based on your localhost time zone as may be your MYSQL database time zone is different than your localhost then you will not get correct data from database.

     $result = $this->db->query('SELECT * FROM '.$table.' WHERE date >= '.date('Y-m-d', time() - (15 * 24 * 60 * 60)).' AND date <= '.date('Y-m-d').' AND '.$condition);
    

提交回复
热议问题