PHP检查有效期函数主要用于网站定时更新,会员有效期设定,订单有效设定等场景.
/*检查是否到期
*可以只传一个日期参数(YYYY-MM-DD H:i:s),和当前时间比对:主要用于定时更新状态等场景
*或者添加一个日期和相差时长,支持年,月,周,日,时,分,秒:主要用于会员时长,订单有效期等固定期限的场景
*ii_check_expireDate('2020-12-01 10:10:10')
*ii_check_expireDate('2020-11-30 13:50:10','5','5')
*/
function ii_check_expireDate($date,$add='0',$type='0'){
$bool = false;
$tnow = strtotime(ii_now());
$tdate = strtotime($date);
switch($type){
case 0:
$edate = strtotime("+".$add." years",$tdate);
break;
case 1:
$edate = strtotime("+".$add." months",$tdate);
break;
case 2:
$edate = strtotime("+".$add." week",$tdate);
break;
case 3:
$edate = strtotime("+".$add." days",$tdate);
break;
case 4:
$edate = strtotime("+".$add." hours",$tdate);
break;
case 5:
$edate = strtotime("+".$add." minutes",$tdate);
break;
case 6:
$edate = strtotime("+".$add." seconds",$tdate);
break;
default:
$edate = strtotime($tdate);
break;
}
if(date('Y-m-d H:i:s',$tnow) >= date('Y-m-d H:i:s',$edate)) $bool = true;
return $bool;
}