これが私がこれまでに持っているものです:
$date = date('Y-m-d h:i:s', strtotime('-7 days'));
$start = date('Y-m-d h:i:s', strtotime($date,'previous Sunday'));
$start を出力すると、次のように返されます: 1969-12-31 06:00:00
私は何を間違っていますか?
$date
タイムスタンプを作成する必要があります
$date = strtotime('-7 days');
$start = date('Y-m-d h:i:s', strtotime('previous Sunday',$date));
あなたは間違った方法で議論をしています:
date('Y-m-d h:i:s', strtotime('previous Sunday', $date));
編集:さらに、$date
フォーマットされた文字列を作成しました。タイムスタンプである必要があるため、コードは次のようになります。
$date = strtotime('-7 days');
$start = date('Y-m-d h:i:s', strtotime('previous Sunday', $date));
日付がタイムスタンプでない場合でもstrtotime
、日付が既に渡されていて、別の種類の文字列形式になっているとします。
$date = '2013-11-10';
$lastsunday = date('Y-m-d',strtotime($date.' last Sunday'));
これにより、日付を「機能する」形式に変換する時間を少し節約できます。
date('Y-m-d h:i:s', strtotime('last Sunday', $date));