Search⌘ K
AI Features

Filter by Date

Explore how to filter data by date in a PHP and MySQL CRUD application. Understand using PHP's strtotime for dynamic date ranges and applying SQL queries with bound parameters to generate accurate reports.

We'll cover the following...

To filter by date, we can use the parameters as::

  • Last week.
  • The present week.
  • Last month.
  • The present month.

Let’s see how we can filter the data by date.

Feature implementation

In our view, we can add this:

PHP
<optgroup label="Date">
<option value="date:<?php
echo date('m/d/y', strtotime("last week monday"));
echo ":";
echo date('m/d/y', strtotime("last week sunday"));
?>
">Last Week</option>
<option value="date:<?php
echo date('m/d/y', strtotime("this week monday"));
echo ":";
echo date('m/d/y', strtotime("this week sunday"));
?>
">This Week</option>
<option value="date:<?php
echo date('m/d/y', strtotime("first day of last month"));
echo ":";
echo date('m/d/y', strtotime("last day of last month"));
?>
">Last Month</option>
<option value="date:<?php
echo date('m/d/y', strtotime("first day of this month"));
echo ":";
echo trim(date('m/d/y')); ?>
">This Month</option>
</optgroup>

Notice that the displaydate was formatted as 09/23/20. We used ...