1

これが私がこれまでに持っているものです:

$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

私は何を間違っていますか?

4

4 に答える 4

4

$dateタイムスタンプを作成する必要があります

$date = strtotime('-7 days'); 
$start = date('Y-m-d h:i:s', strtotime('previous Sunday',$date));
于 2011-01-18T23:13:40.087 に答える
2

あなたは間違った方法で議論をしています:

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));
于 2011-01-18T23:07:44.437 に答える
0

日付がタイムスタンプでない場合でもstrtotime、日付が既に渡されていて、別の種類の文字列形式になっているとします。

$date = '2013-11-10';
$lastsunday = date('Y-m-d',strtotime($date.' last Sunday'));

これにより、日付を「機能する」形式に変換する時間を少し節約できます。

于 2014-02-17T03:10:45.700 に答える
0

PHP ドキュメントごと

date('Y-m-d h:i:s', strtotime('last Sunday', $date));
于 2011-01-18T23:12:16.020 に答える