I have a table TargetOrder
which has from_date and to_date columns along with some other columns. I need to filter the rows whoose from_date and to_date are in the same financial year (1 Apr - 31 Mar).
CodePudding user response:
Try this
$result = TargetOrder::whereBetween(DB::raw("DATE('from_date')"), array($from, $to))->whereBetween(DB::raw("DATE('to_date')"), array($from, $to));
I hope this helps you.
CodePudding user response:
TargetOrder.from_date >= CONVERT(DATETIME, '20100401', 112) AND TargetOrder.to_date < CONVERT(DATETIME, '20110401', 112)
CodePudding user response:
Thanks, everyone for all your Efforts, I finally solved it.
select * from TargetOrder where year(date_add(from_date, INTERVAL 9 MONTH)) != year(date_add(to_date, INTERVAL 9 MONTH));
please post if you have any other work arounds.