1

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

Vikram Anand Bhushan
  • 4,836
  • 15
  • 68
  • 130

2 Answers2

1

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();
alberto-bottarini
  • 1,213
  • 9
  • 21
0

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();
manix
  • 14,537
  • 11
  • 70
  • 107