Good day, dear programmers =))

Before me is the task to display data for several days, for a week and for a month in the 2nd appropriate columns.

The problem is that I do not know how to do it.

How to display data for a specific date I know.

$datesearch = date("Ymd"); $query = mysql_query("SELECT * FROM `table` WHERE date like '%$datesearch%'"); 

Question: how to display data for this week and this month?

    2 answers 2

    During the week:

     SELECT * FROM `table` WHERE date >= adddate(now(), interval - 7 day) 

    Per month:

     SELECT * FROM `table` WHERE date >= adddate(now(), interval - 30 day) 
    • and how to do this week? - Factory
    • via BETWEEN specify the date of Monday and Sunday of the desired week - johniek_comp

    For a specific date:

     SELECT * FROM <table> WHERE date = <yourDate> 

    For a certain period:

     SELECT * FROM <table> WHERE date BETWEEN <dateBegin> AND <dateEnd> 
    • > There is no response for this query: SELECT * FROM <table> WHERE date = <yourDate> - Factory
    • 2
      You use the date as a date, not as a string, and the performance will increase LIKE is not very fast - LIKE
    • > Well, I tried it as a date =)) I’m not a brainworm = brainless =))) $ datesearch = date ("Ymd"); $ query = mysql_query ("SELECT * FROM table WHERE date = '$ datesearch'") or die (mysql_error ()); - Factory
    • I'm sorry in PHP is not strong, I can not answer this) Omul is a good fish, do you happen to live in the Irkutsk region or Buryatia? -
    • I will pretend that I did not understand the hint =)) - Factory