Wouldn't it be nicer to do these calculations in PHP rather than tiring the MySQL?
OzanKurt opened this issue · 0 comments
OzanKurt commented
Wouldn't it be nicer to do these calculations in PHP rather than tiring the MySQL?
/**
* Find items for current year
* @param string $column
* @return $this
*/
public function whereCurrentYear($column = 'created_at')
{
$now = now()->toDateTimeString();
$startOfThisYear = Carbon::parse('first day of this year')->toDateTimeString();
return $this->whereRaw("$column between {$startOfThisYear} and {$now}");
}
laravel-sub-query/src/Traits/LaravelSubQuerySugar.php
Lines 105 to 113 in 42e586f
SELECT * FROM `candidates` WHERE created_at BETWEEN date_format(now() ,'%Y-01-01') and now();
SELECT * FROM `candidates` WHERE created_at BETWEEN "2022-01-01 00:00:00" and "2022-09-28 23:59:59";