You need to compare the date with today's or another specific date (for example -10 days) in the request itself, to make a sample. The date is placed in the cell itself via the time() function:

 $date = date("Ymd",time()); mysql_fetch_array(mysql_query("SELECT * FROM `table` WHERE date('Ym-d',`date`)='".$date."'")); 

Writes an error: mysql_fetch_array() expects parameter 1 to be resource, boolean given

    4 answers 4

    That should help.

      He was not very keen on these features of MySQL , but this is what he once thought up a long time ago:

       mysql_query("DELETE FROM m_uonline WHERE (NOW() - updated) >= 300"); 

      In the m_uonline table in the updated field, the data was entered using CURRENT_TIMESTAMP and it worked, I had to delete users who had not been noted for 300 seconds (5 minutes), NOW () this internal MySQL function forms the current date and time.

      I hope it will come in handy.

        1) Today's Day:

         mysql_fetch_array(mysql_query("SELECT * FROM `table` WHERE date('".$date."')=curdate()")); 

        2) 10 days ago:

         mysql_fetch_array(mysql_query("SELECT * FROM `table` WHERE date('".$date."')=date_add(curdate(),INTERVAL - 10 DAY)")); 
        • Good time, I have a similar problem - I did not begin to create a question here and so many similar things do not work for me: $ tmp = mysql_query ("SELECT * FROM stactions WHERE STR_TO_DATE (fdate, '% Y-% m =% d') <= STR_TO_DATE ('$ datenow', '% Y-% m =% d') AND STR_TO_DATE (tohda, '% Y-% m =% d') <= STR_TO_DATE ('$ datenow', '% Y-% m = % d ') "); - dantelol
        • @dantelol, but why translate to STR_TO_DATE? there is DATE (), DATE_FORMAT - Vfvtnjd

        The TIMESTAMPDIFF (interval, timestamp1, timestamp2) function will help TIMESTAMPDIFF (interval, timestamp1, timestamp2)

        for example for your 10 day difference:

         SELECT TIMESTAMPDIFF (DAY, NOW(), NOW() + INTERVAL 10 DAY) FROM table_date 
        • >> for example, for your difference of 10 days: >> SELECT TIMESTAMPDIFF (DAY, NOW (), NOW () + INTERVAL 5 DAY) FROM table_date A very interesting approach to building SQL queries ... This query, dear @ alter_f4 and @Iranda , does not need the FROM part, and always returns the number 5, which has no relation to the difference of 10 days. - Next_Alex
        • It returns the difference in days between two dates, this example is nothing more than illustrative. Just an example of using a function that can solve this problem. - alter_f4
        • A very interesting approach to building SQL queries ... This query, dear @ alter_f4 and @Iranda, does not need the FROM part and always returns the number 5, which has no relation to the difference of 10 days. - alter_f4
        • I am aware of the information, the link to which I gave. I just do not see the point of making a left request from information already available in the response. - Next_Alex
        • "always returns the number 5, which has no relation to the difference of 10 days." Judging from this, it was not quite clear what you understand, what is written in your link =) - alter_f4