我有日期加入,只想比较日期和月份。如下所示,如果员工在 1 月 1 日至 6 月 30 日之间加入,则会输出 Jan-June。
但是,我现在的问题是,如果加入日期是在 7 月到 12 月之间,它仍然会输出为 Jan - June。我的代码有问题吗?谢谢。
如果我echo $date_join
,输出将为 15/08
$date_join =(date("d/m", strtotime($row['date'])));
if (($date_join >= '01/01') && ($date_join <= '30/06'))
{
echo 'Jan - June';
}
else if (($date_join >= '01/07') && ($date_join <= '31/12'))
{
echo 'July - Dec';
}
最佳答案
试试这个。
$date_join_month =date("n", strtotime($row['date']));
$date_join_month=inval($date_join_month);
if ($date_join_month >= 1 && $date_join_month <= 6)
{
echo 'Jan - June';
}
else if ($date_join_month >= 7 && $date_join_month <= 12)
{
echo 'July - Dec';
}
关于php - 日期范围的 If 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41117747/