Vimalnath Vimalnath - 1 year ago 107
PHP Question

Add 15 minutes to current time and snap to 15 minute intervals

I need to add 15 minutes to the current time.
For eg : now is

, need to add 15 minutes, so now it will be
, but i need to set 21:15 ,that is , it should be in multiples of
Help help/guidance would be of good help.

$current_date_time = date('d/m/Y H:i:s');
$current_date = date("d/m/Y H:i", strtotime($current_date_time."+15 minutes"));
echo $current_date;exit;

Answer Source

Here's a simple example

//what time is it?

//how long is our interval?

//we can calculate when the last interval started by subtracting $t % $interval
$last = $t - $t % $interval;

//so now we know when the next interval will start...
$next = $last + $interval;

echo "Next interval at ".strftime('%H:%M:%S', $next)."\n";

You look like you might want to add 2*$interval to the last interval, but you should be able to adapt this to suit you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download