Question

how can find out the difference between time, for example the appointment time is

4:30 PM but i want to send a notification via cron job 30 mins ,15 mins or 5 mins

before 4:30 PM

but i cant figure out how to get the time difference so that i can make an if statement to notify for ex if set to 30 mins the email will be sent at 4:00 PM

ex:

$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=======

} 
Was it helpful?

Solution

Here's what you want:

$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);

OTHER TIPS

$setting is a string, so you can't do - $setting and expect it to work. You have to add the - to the string itself:

$difference = strtotime('-' . $setting , $notiftime);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top