2017-08-13 111 views
0

我試圖在當前每週輸出當前在這一年。我使用下面顯示的代碼,但在使用星期一至星期日時不起作用。使用strtotime輸出所有星期不工作星期一至星期日,但是用於星期六PHP

for ($i = 0; $i < date("W"); $i++) 
{ 
echo '<option value="' . date("W", strtotime("this monday - $i week")) . '">' . date("M j Y", strtotime("this sunday - $i week")) . " - " . date("M j Y", strtotime("this saturday - $i week")) .'</option>'; 
} 
+0

能否請你確定你是什麼意思'使用星期一Sunday'當它不工作呢? – Fotis

回答

0

道歉所有,我發現後發佈這個很快的解決方案。我意識到我需要添加而不是減去這個。這使我的輸出:

「2017年8月14日 - 2017年8月20日」

'<option value="' . date("W", strtotime("this monday - $i week")) . '">' . date("M j Y", strtotime("this monday - $i week")) . " - " . date("M j Y", strtotime("next sunday + $i week")) .'</option>' 
相關問題