I have a table called entries and its created_at is defined as DATE type. How do I get a record, for example, of 15 March?
What I've tried
$post = Entry::where(\DB::raw('DATE(created_at)'),'=',date('2015-03-15'))->get()->toJSON();
but it returns empty result.
Migration
Schema::create('entries', function(Blueprint $table)
{
$table->increments('id');
$table->integer('intern_id');
$table->integer('company_id');
$table->longText('content');
$table->date('created_at')->unique();
$table->date('updated_at')->unique();
});
There are currently 3 records with dates of each of 2015-03-15, 2015-03-19 and 2015-03-20
Use this
$post = Entry::where("created_at","2015-03-15")->get()->toJSON();
You can use this form:
$post = Entry::where('created_at', '>=', '2015-03-15')->get()->toJSON();
Carbon Update
$date = \Carbon\Carbon::create(2015, 3, 13, 0, 0, 0);
$u = Entry::where('created_at', '>=', (string) $date)
->where('created_at', '<', (string) $date->addDays(1))
->get()
->toJSON();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With