PHP Adding 15 minutes to Time value

Viewed 158711

I have a form that receives a time value:

$selectedTime = $_REQUEST['time'];

The time is in this format - 9:15:00 - which is 9:15am. I then need to add 15 minutes to this and store that in a separate variable but I'm stumped.

I'm trying to use strtotime without success, e.g.:

$endTime = strtotime("+15 minutes",strtotime($selectedTime)));

but that won't parse.

9 Answers

strtotime returns the current timestamp and date is to format timestamp

  $date=strtotime(date("h:i:sa"))+900;//15*60=900 seconds
  $date=date("h:i:sa",$date);

This will add 15 mins to the current time

get After 20min time and date

function add_time($time,$plusMinutes){

   $endTime = strtotime("+{$plusMinutes} minutes", strtotime($time));
   return date('h:i:s', $endTime);
}

20 min ago Date and time

date_default_timezone_set("Asia/Kolkata");
echo add_time(date("Y-m-d h:i:sa"),20);

In one line

$date = date('h:i:s',strtotime("+10 minutes", strtotime($date)));

You can use below code also.It quite simple.

$selectedTime = "9:15:00";
echo date('h:i:s',strtotime($selectedTime . ' +15 minutes'));

Current date and time

$current_date_time = date('Y-m-d H:i:s');

15 min ago Date and time

$newTime = date("Y-m-d H:i:s",strtotime("+15 minutes", strtotime($current_date)));

Quite easy

$timestring = '09:15:00';
echo date('h:i:s', strtotime($timestring) + (15 * 60));
Related