我试图确定当前日期是否位于两个不同日期的预定范围内。我目前的工作正常;尽管我需要它忽略年字段,只关注日和月,使其能够在未来几年工作,而不必每次都更改代码中的日期。$today = date('Y-m-d');$today = date('Y-m-d', strtotime($today));$winter = date('Y-m-d', strtotime("21/12/2020"));$spring = date('Y-m-d', strtotime("20/06/2020"));if( ($today >= $winter) && ($today <= $spring) ) { echo "Generic in timeframe message";} else { echo "Not in timeframe";}
1 回答
MMMHUHU
TA贡献1834条经验 获得超8个赞
如果您希望它始终比较当年的日期,您可以让 PHP 告诉您当前年份,并在冬季/春季日期中使用它:
$yr = date("Y"); //get the current year in yyyy format
$winter = date('Y-m-d', strtotime("21/12/".$yr));
$spring = date('Y-m-d', strtotime("20/06/".$yr));
- 1 回答
- 0 关注
- 75 浏览
添加回答
举报
0/150
提交
取消