问题
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