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

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

``````<?php
\$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;
``````

Here's a simple example

``````//what time is it?
\$t=time();

//how long is our interval?
\$interval=15*60;

//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