我在db中有一个日期字段。
希望我能清楚自己
答案 0 :(得分:1)
SELECT DAYOFWEEK(date) as wd FROM table WHERE wd > 1 AND wd < 6 AND date >= CURRENT_TIMESTAMP() ORDER BY date ASC LIMIT 1;
答案 1 :(得分:0)
$from = strtotime('saturday');
$to = strtotime('tueseday') - 1; // whole monday
mysql_query('SELECT * FROM table WHERE date >= ' . $from . ' AND date <= ' . $to . ' ORDER BY date LIMIT 1');
答案 2 :(得分:0)
这将从数据库中返回您需要的数据:
//once you've connected to the DB
$db_query= "SELECT * FROM table
WHERE DATEDIFF(CURDATE(), date)>0
AND (DAYOFTHEWEEK(date)<3 OR DAYOFTHEWEEK(date)==7)
ORDER BY date
LIMIT 0,1";//limits it to one (date) result
$result=mysql_query($db_query);
if(!$result){ die('ERROR: Query failed.'); }
这将在屏幕上打印结果行:
while($ROW=mysql_fetch_assoc($result))
{
echo "<p>date: {$ROW['date']}</p>";
//do the same for all the fields you want like so:
echo "<p>other field: {$ROW['other field']}</p>";
}
mysql_free_result($result);
答案 3 :(得分:0)
SELECT * FROM table WHERE DATEDIFF(CURDATE(),date)&gt; 0 AND(DAYOFWEEK(date)in(1,2,7)ORDER BY date LIMIT 0,1