简体   繁体   中英

Get Last 3 days data from table CodeIgniter

I am trying to get the last 3 days' data from the table with this query

$this->db->where('booking_date BETWEEN DATE_SUB(NOW(), INTERVAL 3 DAY) AND NOW()');

but my problem is the booking date is in UNIX timestamp like this 1600811452.

UNIX_TIMESTAMP() gives you current Unix timestamp. Calculate the number of seconds that exists on a day. Multiply by 3. Subtract from UNIX_TIMESTAMP() . There you have the start date. UNIX_TIMESTAMP() is the end date.

Or

$this->db->where('booking_date BETWEEN UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 3 DAY)) AND UNIX_TIMESTAMP(NOW())');

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