如何找出时间之间的差异,例如约会时间
下午4:30但我想通过cron job发送通知30分钟,15分钟或5分钟
下午4:30之前
但我无法弄清楚如何获得时差,以便我可以制作一个if语句 要通知ex,如果设置为30分钟,则电子邮件将在下午4:00发送
例如:
$setting = "30 minute";//set to notify 30 min before appointment
$notiftime = "4:30 PM";//time of the appointment
$notiftime = strtotime($notiftime);
$difference = strtotime( '-' $setting , $notiftime);
$current = date('h:ia'); //gets current time
$current = strtotime($current);
if ( $current <= $difference){
//send email script=======
}
答案 0 :(得分:1)
$setting
是一个字符串,因此您无法执行- $setting
并期望它能够正常工作。您必须将-
添加到字符串本身:
$difference = strtotime('-' . $setting , $notiftime);
答案 1 :(得分:1)
这是你想要的:
$appointment = "4:30 PM";//time of the appointment
$delay = 30 * 60; //set to notify 30 min before appointment
$appointment = strtotime($appointment);
$notifytime = date('h:ia', $appointment - $delay);