Search by month

Hi people,
I have a database column called date type is date.

I am using a search to bring results by date. My code for this is:

                                        <input type="date" name="date" value="<?php if(isset($_GET['date'])){ echo $_GET['date']; } ?>" class="form-control">

If for example I made an entry on January 5th the date shows 2023-01-05 in the date field

What i want to do is search by Month so all records for that Month would show.

So if i searched January it would include the results including January 5th. Or if I searched say December it would show any results that were from any date in December and so on ?

I have tried this but its not working.

"SELECT * FROM staffcall WHERE month(date) = ?"

Maybe a search input using month and year as after 12 months it would repeat ?

Any advice please ?

Many Thanks

Yes, you would want to compare the year and month. The most efficient method, since it can use an index on the column, would be to build the YYYY-MM-DD date of the first and last day of the month, then use WHERE date BETWEEN ? AND ?

Without all the code to reproduce the problem, we cannot help with what your code is doing. The problem could be in the form, in the form processing code, in the database specific code, in the code testing and using the result from the query.

Sponsor our Newsletter | Privacy Policy | Terms of Service