Reputation: 4896
I have a table where there is a column which has event date
but the column is of type varchar.
The date is saved in form of dd-mm-yy
now I want to get all the events whose date is greater than today's date.
My code which doesnot work looks like this
$cat=Event::where('date','>=',date('d-m-Y'))->get();
But its not working it is getting me all the events
Any help would be appreciated
Thanks
Upvotes: 1
Views: 1195
Reputation: 1231
If your columntype is date, you could use Carbon:
use \DateTimeZone;
use Carbon\Carbon;
use App\BlogVideo;
$today = Carbon::now(new DateTimeZone('Europe/Rome'));
Event::where('date','>=',$today)->get();
Upvotes: 1
Reputation: 14747
If column is varchar
type there is nothing you can do, except change the column datatype to date
or datetime
. Then, just do what you did before:
Event::where('date','>=', new \DateTime('now'))->get();
Upvotes: 0