hamzasgd
hamzasgd

Reputation: 253

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.

Upvotes: 0

Views: 331

Answers (1)

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())');

Upvotes: 1

Related Questions