Select record(s) from mysql table where date is greater than or equal to today

你离开我真会死。 提交于 2021-02-20 02:13:27

问题


I am working on a project that has rows in the database that contains a date. I want to echo the data for the fields that have a date that is equal or greater to today. I have looked at other post and tried a lot of different methods and have yet to succedd. Currently what I have returns an error when I do >= but when I just do = with the statement below, I get all rows from the database.

  $sql = "SELECT * FROM drives WHERE ddest = '{$trimmed}' AND 'leave_date' => DATE_FORMAT(CURDATE(), '%m/%d/%Y') LIKE '%$trimmed%' ORDER BY timeago DESC";

回答1:


Try this

  $sql = "SELECT * FROM drives WHERE ddest = '{$trimmed}' AND 'leave_date' >= NOW() LIKE '%$trimmed%' ORDER BY timeago DESC";

else this,

  $sql = "SELECT * FROM drives WHERE ddest = '{$trimmed}' AND 'leave_date' >= DATE_FORMAT(CURDATE(), '%m/%d/%Y') LIKE '%$trimmed%' ORDER BY timeago DESC";



回答2:


try this query if you want a date that is equal or greater to today.

select * from drives where day(now()) <= day(ddest) and year(ddest) >= year(now());



回答3:


A valid query might look something like this:

SELECT * 
  FROM drives 
 WHERE ddest = '{$trimmed}' 
   AND leave_date >= CURDATE()
 ORDER 
    BY timeago DESC

Any remaining problems are more likely to do with the way you're handling our data rather then with the query itself.



来源:https://stackoverflow.com/questions/41421524/select-records-from-mysql-table-where-date-is-greater-than-or-equal-to-today

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!