我遇到了一些挑戰,試圖找出如何捕捉2周工資的范圍。
我將如何修改-2W案例?
$from = null。
$to = null;
switch ($range) {
case '1D'/span>:
//代碼...: '1D': //代碼
$from = date('Y-m-d ', strtotime('today') . '00:00:00'。
$to = date('Y-m-d ', strtotime('day')) . '23:59:59'。
$objectView->historyFrom = date('D, F j') 。
$objectView->historyTo = date('D, F j') 。
break。
case '1W':
//代碼...: '1W' : //代碼...
$from = date('Y-m-d ', strtotime('monday this week')) 。'00:00:00'。
$to = date('Y-m-d ', strtotime('sunday this week')) 。'23:59:59'。
$objectView->historyFrom = date('D, F j', strtotime('monday this week'))。
$objectView->historyTo = date('D, F j', strtotime('sunday this week'))。
break。
case '-1W':
//代碼...: '-1W': //代碼
$from = date('Y-m-d ', strtotime('monday last week')) . '00:00:00'。
$to = date('Y-m-d ', strtotime('sunday last week')) . '23:59:59'。
$objectView->historyFrom = date('D, F j', strtotime('monday last week'))。
$objectView->historyTo = date('D, F j', strtotime('sunday last week'))。
break。
case '-2W':
//代碼...: '-2W': //代碼
$from = date('Y-m-d ', strtotime('monday previous to last week') ) . '00:00:00'。
$to = date('Y-m-d ', strtotime('sunday last week')) . '23:59:59'。
$objectView->historyFrom = date('D, F j', strtotime('monday last week'))。
$objectView->historyTo = date('D, F j', strtotime('sunday last week'))。
break。
default:
//代碼...: default.
$from = date('Y-m-d ', strtotime('day')) . '00:00:00'。
$to = date('Y-m-d ', strtotime('day')) . '23:59:59'。
$objectView->historyFrom = date('D, F j') 。
$objectView->historyTo = date('D, F j') 。
break。
}
uj5u.com熱心網友回復:
你真的應該看看DateTime可能DatePeriod。 但是要用現有的代碼來回答這個問題,我想你需要兩種格式,一種是今天是星期一,另一種是今天不是:
if(date('w'/span>) == '1'/span>) {
$from = date('Y-m-d ', strtotime('-2 weeks') 。
/or '-14 days'。
} else {
$from = date('Y-m-d', strtotime(' previous monday -2 weeks'))。
/or 'previous monday -14 days'.
}
有人可能會找到一種對兩者都適用的格式。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/311889.html
標籤:
