我有这段代码:
$curdate = '22-02-2011';
$mydate = '10-10-2011';
if($curdate > $mydate)
{
echo '<span class="status expired">Expired</span>';
}
这将回显"已过期",但不应该,因为$mydate在未来,因此比$curdate小,但PHP只查看前两个数字22和10,而不是整个字符串。我该怎么解决这个问题?
谢谢
尝试先将它们都转换为时间戳,然后比较这两个转换后的值:
$curdate=strtotime('22-02-2011');
$mydate=strtotime('10-10-2011');
if($curdate > $mydate)
{
echo '<span class="status expired">Expired</span>';
}
这将把它们转换为自1970年1月1日以来的秒数,因此您的比较应该有效。
$curdate = strtotime('22-02-2011');
$mydate = strtotime('10-10-2011');
$row_date = strtotime($the_date);
$today = strtotime(date('Y-m-d'));
if($row_date >= $today){
-----
}
$currentDate = date('Y-m-d');
$currentDate = date('Y-m-d', strtotime($currentDate));
$startDate = date('Y-m-d', strtotime("01/09/2019"));
$endDate = date('Y-m-d', strtotime("01/10/2022"));
if (($currentDate >= $startDate) && ($currentDate <= $endDate)) {
echo "Current date is between two dates";
} else {
echo "Current date is not between two dates";
}
if(strtotime($curdate) > strtotime($mydate))
{
...
}
非常简单
$curdate = '2011-02-22';
$mydate = '2011-10-10';
if($curdate > $mydate)
{
echo '<span class="status expired">Expired</span>';
}
$curdate
的硬编码变量是很愚蠢的。 - drudge