Laravel 5.2比较字符串的日期?

I have a table that contains two dates: start_date and end_date. Both of these columns are string. When I try to query to get the records comparing against these dates, Laravel treats them as strings, instead of dates.

For example, for this query:

Schedule::whereDate('start_date','<=',date('m/d/Y'))->whereDate('end_date','>=',date('m/d/Y'))->get();

No results are returned, which is not correct.

Any thoughts? Or any other way to compare dates that are strings?

Thanks.

You need to make these columns datetime instead of string:

$table->dateTime('start_date');
$table->dateTime('end_date');

Also, it's a good idea to add these columns to the $dates array:

protected $dates = ['created_at', 'updated_at', 'start_date', 'end_date'];

Have a look at Carbon. Gonna work great for time-stuff

http://carbon.nesbot.com/docs/