有沒有辦法檢索到最近日期的記錄到給定的日期變量?mysql找到下一個日期後給出
例如:
日期今天是Thursday, 10th January 2012
我的數據庫有固定裝置的列表,從中我想列出「下週的」夾具這是下週三即:Wednesday, 16th January 2012
如何我是否得到一個文件來輸出在日期列中有這個的所有行?
在此先感謝!
編輯:
這是我的表樣本數據 - bowl-track_fixtures
:
| fixture_id | league_id | fixture_team_1 | fixture_team_2 | fixture_date |
---------------------------------------------------------------------------------------
| 1 | 2 | 5 | 6 | Wednesday, 30th January |
| 2 | 2 | 4 | 1 | Wednesday, 30th January |
| 3 | 2 | 2 | 3 | Wednesday, 30th January |
| 1 | 2 | 5 | 6 | Wednesday, 06th February |
| 2 | 2 | 4 | 1 | Wednesday, 06th February |
| 3 | 2 | 2 | 3 | Wednesday, 06th February |
etc..
我希望系統只顯示我這是最近和後今天的日期行。
我試過以下;
SELECT * FROM `bowl-track_fixtures` WHERE STR_TO_DATE(`fixture_date`, '%l, %d%S %F %Y') >= NOW() ORDER BY STR_TO_DATE(`fixture_date`, '%l, %d%S %F %Y') LIMIT 1;
然而,這不返回任何結果
@Nicarus
這是MySQL的代碼我使用:
SELECT fixture_id, MIN(STR_TO_DATE(
fixture_date, '%l, %d%S %F %Y'
)) AS `next_fixture_date`
FROM `bowl-track_fixtures`
WHERE STR_TO_DATE(
`fixture_date` , '%l, %d%S %F %Y'
) & gt ; = NOW()
GROUP BY `fixture_id`
)b ON (a.`fixture_id` = b.`fixture_id`)
AND (
STR_TO_DATE(
a.`fixture_date` , '%l, %d%S %F %Y'
) = b.`next_fixture_date`
)
LIMIT 0 , 30
,並返回此:
MySQL said:
#1305 - FUNCTION db.STR_TO_DATE does not exist
您的日期是實際日期,還是他們的字符串格式? – Ryan
最近或最近的AND更大的日期? – 2013-01-10 04:02:17
字符串格式我使用strtotime轉換我的php文件 –