Home  >  Q&A  >  body text

How to query dates between two dates in the same column in MySQL

<p>I have a table called holiday_master with the following columns</p> <pre class="brush:php;toolbar:false;">| Id | Title | Date | |:---|:-------|:------------------------| | 1 | Christmas | 12-25-2021 - 12-30-2021 | | 2 | Celebration Festival | 11-30-2021 - 12-02-2021 |</pre> <p>Suppose I have the current date 2021-12-27, it appears in the first row, I want to get that record, thank you in advance :)</p>
P粉083785014P粉083785014410 days ago536

reply all(1)I'll reply

  • P粉245003607

    P粉2450036072023-09-06 16:28:07

    Poor database design can cause many problems. Your database is unavailable. Date should be in timestamp or date format split into two columns: start_date and end_date

    Then you can execute

    SELECT * FROM holiday_master WHERE start_date < :date AND end_date > :date
    

    reply
    0
  • Cancelreply