I am working on a code which will send users reminders like 10 minutes,2 hours, a day, one week before their event is due.

I will like to get the datetime after the reminder has been removed from the startdate

$startdate = "2010-07-10 01:00:00"; // date chosen by the user
$reminder  = "10 * 60"; // 10 minutes converted to seconds
//I will like to get the time after each of the following has been reducted.

$reminder = "60*60" // 1 hour
$reminder = "24*60*60" // 1 day
$reminder = "24*7*60*60" 1 week

Thanks in advance.

Check this code.

<?

function  timeAfter($timestamp, $granularity=2, $format='Y-m-d H:i:s'){

        $difference = $timestamp - time();
       
        if($difference < 0) return '0 seconds ago';             // if difference is lower than zero check server offset
        elseif($difference < 864000){                                   // if difference is over 10 days show normal time form
       
                $periods = array('week' => 604800,'day' => 86400,'hr' => 3600,'min' => 60,'sec' => 1);
                $output = '';
                foreach($periods as $key => $value){
               
                        if($difference >= $value){
                       
                                $time = round($difference / $value);
                                $difference %= $value;
                               
                                $output .= ($output ? ' ' : '').$time.' ';
                                $output .= (($time > 1 && $key == 'day') ? $key.'s' : $key);
                               
                                $granularity--;
                        }
                        if($granularity == 0) break;
                }
                return ($output ? $output : '0 seconds').' after';
        }
        else return date($format, $timestamp);
}

$ts = strtotime('2010-07-15 7:00:00');
echo timeAfter($ts,4);
exit;

?>

Thanks, but it is not what i was expecting. I
I am getting close but i still have a problem
let's say

$reminder ="300"; // 5 minutes * 60 seconds (to convert to seconds)
$timefromreminder = date('h:i:s', strtotime("-$reminder seconds"));
// this will give 5 minutes minus the current time
//but what i am looking for is to be able to do this
$event_start_time = '11:45:00';
$timefromreminder2 = date('$event_start_time', strtotime("-$reminder seconds"));
//Now it does not give 11:40:00 instead it does nothing and gives the same 11:45:00

I want to be able to delete 5 minutes from a time i specify

Get the current time as a timestamp [ $wk = strtotime("$my_date $my_time"); ]

Subtract your 5 minutes / 300 seconds from it [ $wk2 = $wk - 300; ].

Then you can do whatever you need to do with it:
e.g. display it: [ echo date("Y-m-d H:i:s",$wk2); ]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.