CodeIgniter Forums
get result from database equal today - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: get result from database equal today (/showthread.php?tid=79163)



get result from database equal today - viracoders - 05-02-2021

I need to get posts of today from database using where

PHP Code:
// Get Today Time
$time Time::today('America/Chicago''en_US');
$today $time->toDateString(); // 2021-02-05

$testModel = new \App\Models\TestModel();
$results $testModel->getLatest($today); 

in Model (getLatest): 

PHP Code:
$builder $this->db->table('posts p');
$builder->select('p.*');
$builder->where('???????????????',$today);
$builder->orderBy('created_at''ASC');
$prices $builder->get()->getResultObject(); 

How do can I generate this query using where OR another method?


RE: get result from database equal today - includebeer - 05-02-2021

You can write custom where clause, see number 4 Custom string on this page: http://codeigniter.com/user_guide/database/query_builder.html#looking-for-specific-data

Try this:
PHP Code:
$builder->where('created_at >= CURRENT_DATE'); 

If CI try to protect the field name and mess the query, try this:
PHP Code:
$builder->where('created_at >= CURRENT_DATE'nullfalse);