3

日付を計算したいときに問題があります。簡単な例:

2013-09-01開始日があり、月に30日あります。私の仕事は、月末の 10 日前にユーザーに警告する必要があります (2013-09-20警告メッセージが必要ですit's 10day more for end of this month)。だから、誰もがそれを計算するのに役立つアイデアを持っています. なぜなら私は+, -, *,/デートができないのが好きだからです。今、私は次のようなデータです

<?php
    date_default_timezone_set('Asia/Phnom_Penh');
    $current = time();
    $start = 1380188957;
    echo 'Start date: '. date('Y-m-d', $start) ."\n";
    echo '<br/>';
    $repeat = 30;
    $enddate = time() + ($repeat * 24 * 60 * 60);
    echo 'end date: '. date('Y-m-d', $enddate) ."\n";

助けてくれてありがとう。

4

2 に答える 2

2

毎月 31 日というわけではありません。PHP の関数tで文字列フォーマット パラメータのオプションを使用して、任意の月の日数を取得できます。date()

// Current time as unix timestamp   
$now = time();

// Number of days in current month
$days_this_month = date("t", time());

// Last day of the current month as a unix timestamp;
$end_of_month = strtotime(date("Y-m-t", time()));

// Ten days before the end of the month as a unix timestamp
$ten_days = strtotime('-10 days', $end_of_month);

これで、月末の 10 日前かどうかを確認できます。

if($now > $ten_days) {

    // Do something
}
于 2013-09-27T03:38:54.350 に答える