私はこの形式で今日の日付を取得できるようにするこのコードを持っています:
$today = date("d-m-Y");
次に、このクエリ:
while ($row1 = mysql_fetch_array($queryenddate)) {
$end_date=$row1['end_date'];
}
終了日は次のように出力されます: 12-02-2012
この 2 つの日付を比較するにはどうすればよいですか? 私は何をする必要がありますか?ありがとう
あなたはこれを比較することができます
if(strtotime($date1)>strtotime($date2))
あなたはただ使うことができますDateTime
$today = new DateTime();
$date = DateTime::createFromFormat("d-m-Y", $end_date);
if ($today > $date) {
// Totaay is more current
}
if ($today->format("m") == $date->format("m")) {
// they have same month
}
このようなこともできます
$diffrence = $today->diff($date); //enddate is "01-01-2010"
var_dump($diffrence);
出力
object(DateInterval)[3]
public 'y' => int 2
public 'm' => int 8
public 'd' => int 24
public 'h' => int 0
public 'i' => int 0
public 's' => int 0
public 'invert' => int 1
public 'days' => int 998
strtotime() 関数を使用して日付を数値に変換し、比較または操作に使用できます。
$today = date("d-m-Y");
$end_date='02-09-2012';
echo $today;
echo "<br>".$end_date;
$diference= (strtotime($end_date)-strtotime($today))/86400;
$diference= abs($diference);
$diference= floor($diference);
echo "<br>".$diference;