0

I have a date table like below :

Schema::create('dates', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->dateTime('date');
    $table->float('price');
    $table->timestamps();
});

Now I have a form that submits an start and a finish date so I have 2 variables

$start_date;
$end_date

How can I sort my date table ascending and show the dates between the start_date and the end_date?

1
  • What format are $start_date and $end_date ? Commented Apr 2, 2019 at 8:04

2 Answers 2

2

You can use the whereBetween() method:

\DB::table('dates')
    ->whereBetween('date', [$start_date, $end_date])
    ->orderBy('date', 'asc')
    ->get();

If you have a model for this table you can use it directly instead of the DB facade.

Sign up to request clarification or add additional context in comments.

Comments

-1

You can use Eloquent like below:

   YourModel::whereDateBetween(‘date’,$start_date,$end_date)->orderBy->(‘date’,’asc’)->get();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.