0

I have a column in the MySQL database that stores data as Date 17-6-2021 for example

the user choose a month and year from input fields as follow

<form method="POST">
    <table>
        <tr>
          <td><label>choose month</label></td>
          <td><input name="month">
        </tr>
        <tr>
          <td><label>choose year</label></td>
          <td><input name="year">
        </tr>
    </table> 
    <input type="submit" name="add1" value="submit">
</form>

I want to compare the date chosen by the user with dates stored in the database to get all values within the month and the year what function should I use?? my purpose here is to generate a monthly report based on user choices

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Use the `YEAR()` and `MONTH()` functions. – Barmar Jun 17 '21 at 15:24
  • Step one: Don't store a date as `d-m-Y`. As you have it, you'll have to use `LIKE` or a collection of string mutating functions -- YUCK. Save yourself the headache. Redesign your database table. https://softwareengineering.stackexchange.com/q/422047 , https://stackoverflow.com/questions/7817724/is-it-a-good-idea-to-use-string-data-type-for-dates-in-mysql-instead-of-using-da , https://stackoverflow.com/q/47764226/2943403 – mickmackusa Jun 17 '21 at 15:24
  • i already have the database data stored like this because it get the data from date field thats why i want to deal with data stored in this way – Tammam Wardi Jun 17 '21 at 15:37
  • i used the MONTH and YEAR but i didn't get the correct result – Tammam Wardi Jun 17 '21 at 15:38
  • please read https://meta.stackoverflow.com/questions/333952/why-should-i-provide-a-minimal-reproducible-example-for-a-very-simple-sql-query and make a [mre] – nbk Jun 17 '21 at 15:52
  • Store the date using a date data type – Strawberry Jun 17 '21 at 15:56

0 Answers0