1
今日の今日の日付(m-d-Y)を取得して30日を追加したいと考えています。私はこれをmySQLデータベースに入れます。それから毎日、それは14日に近いときに何日残ったかを言うでしょう。phpどのように日付を減算または追加するには?
$today = strtotime(date('Y-m-d H:i:s'));
$expireDay = date('m-d-Y', strtotime("+30 days"));
$timeToEnd = $expireDay - $today;
if ($timeToEnd <= strtotime("$expireDay - 14 days")// this is not correct syntax
{
echo "less than 14 days";
echo $timeToEnd('d')//here is where I am having problems with my syntax
} else {
echo "more than 14 days";
}
'$ expireDay'は整数ではなく文字列です。 'strtotime'を使うと、それを使ってデータを得ることができます。 'strtotime(date( 'Y-m-d H:i:s'))'は 'time()'でもかまいません。 – chris85
この質問はほぼ毎日尋ねられています。 http://stackoverflow.com/questions/365191/how-to-get-time-difference-in-minutes-in-php – Axalix