How to add hours and minutes in PHP?

Here we’ll provide the simplest way to add minutes, hours and seconds to time using PHP. In PHP, using date() and strtotime() function you can easily increase or decrease time.

1. Code:

    <?php 
	
	function addHoursAndMinutes($date, $hour = 0, $minute = 0, $offset = ''){
		$hour = strval($hour);
		$minute = strval($minute);
		$date = strtotime($offset . $hour . " hours " . $offset . $minute . " minutes", strtotime($date));
		$result = date("Y-m-d H:i:s", $date);
		return $result;
	}
	$str = addHoursAndMinutes("20-06-2022 2:12:23", 13, 34 );
	echo($str);
    ?> 

2. Example:

Input:

("20-06-2022 2:12:23", 13, 34 )

Output:

2022-06-20 15:46:23