2012-01-18 84 views
0

使用SQL查詢我有了這裏面有包含星期幾,如「星期一」,「星期二」等獲取當前(系統)日在PHP

如何列的表這個MySQL數據庫我查詢數據庫並將此列內容與當前(系統)日相匹配?

喜歡說

select .... where tablename.columnname = systemday 

感謝。

回答

-3
<?php 
$day=date('D'); 

$sql='select * from the_table where the_table.'.$day.'=systemday'; 
?> 
+0

發佈的SQL語句不正確,應該讀取「the_table.column = $ day」 – Neo 2012-01-18 13:19:38

1

您是否嘗試過搜索?

反正我希望你想這樣的事情,

$ cur_day =日期( 'd');

select .... where tablename.columnname = $cur_day;

0
WHERE tablename.columnname = substr(dayname(now()),1,3) 

WHERE tablename.columnname = date_format(now(),'%a') 

但是請注意,它可以通過區域設置的影響。

0

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_weekday

Returns the weekday index for date (0 = Monday, 1 = Tuesday, … 6 = Sunday). 

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_dayofweek

​​

例子:

SELECT * FROM mytable WHERE dayOfTheWeek=WEEKDAY(NOW()) 

此外,你可以做到這一點使用PHP`s strftimedate功能:

$query1 = mysqli_query('SELECT * FROM mytable WHERE dayOfTheWeek="'.date('N').'"'); 
$query2 = mysqli_query('SELECT * FROM mytable WHERE dayOfTheWeek="'.strftime('%u').'"'); 

但是,我認爲,這是更好的PHP,只有這樣,才能產生這一點。