我写了一些代码来比较日期,这里我遇到的问题是当我输入日期时 2012/mar/23 给出的输出有时正确,有时错误。当我输入日期为 2012/03/23 时也给出输出有时正确,有时错误。我该如何解决这个问题?
<?php
$month = 2;
$year = 2012;
$saturday = strtotime('First Saturday '.date('F o', mktime(0,0,0, $month, 1, $year)));
echo date('Y/M/d', $saturday);
$sat1 = strtotime($saturday);
echo "<br/>";
$season1 = strtotime ( '+12 week' , $saturday);
$season2= date ( 'Y/M/d' , $season1 );
echo $season2;
$season = strtotime($season1);
echo "<br/>";
$date = $_POST["date"];
echo $date;
$date1 = strtotime($date);
echo "<br/>";
$abc = strtotime ('+1 week' , $season1);
$abc = date ('Y/M/d', $abc);
echo "<br/>";
echo $abc;
$abc1 = strtotime($abc);
if ($date1 <= $abc1)
{
if ($date1 <= $season)
{
echo "League already opened";
}
else if($date1 > $season)
{
echo "league successfully closed";
}
}
else
{
echo "league 1 closed";
}
if(!isset($POST['submit'])) {
?>
<form method="post" action=" ">
<label>enter date in YYYY/MM/DD format</label>
<input type="text" name="date" size="10" />
<input type="submit" value="submit" name="submit">
</form>
<?
}
?>
并在输出中显示 if condition.before 中的 msg 提交表单