Welcome Guest, Not a member yet? Register   Sign In
get result from database equal today
#1
Question 
(This post was last modified: 05-02-2021, 02:13 AM by viracoders.)

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?
Reply
#2

You can write custom where clause, see number 4 Custom string on this page: http://codeigniter.com/user_guide/databa...cific-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); 
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB