-4

Is there a way to substitute dates from database in laravel? For example i have 2 columns named: begin_date(25.04.2023), end_date(26.04.2023). is there way to substitute end_date to begin_date and the result to be 26-25 = 1 day ?

  • So when you say "substitute", you actually mean _subtract_? MySQL has date functions such as [`DATEDIFF()`](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_datediff) – CBroe Apr 25 '23 at 09:30
  • (As for using native MySQL functions with the Eloquent ORM query builder, see https://stackoverflow.com/a/17087235/1427878) – CBroe Apr 25 '23 at 09:31

1 Answers1

1

Yes, you can substitute dates (date1-date2) in Laravel using the whereBetween method

`$startDate = '2023-01-01'; $endDate = '2023-04-25';

$results = DB::table('your_table') ->whereBetween('created_at', [$startDate, $endDate]) ->get();`