I have stored the date and time in database like this 2015-06-31 14:00
And i want to add some hours
to the date
field through variable how can i add
<?php
//set an date and time to work with
$start = '2015-06-31 14:00';
$hours='05:00';
//display the converted time
echo date('Y-m-d H:i',strtotime("+{$hours} hours",strtotime($start)));
?>
Try this
<?php
$start = '2015-10-31 14:00';
$hours = '05:00';
$date = new DateTime($start);
$date->modify(sprintf("+%d hours", $hours));
echo $date->format("Y-m-d H:i");
?>
Output:
2015-10-31 19:00
Check this
//set an date and time to work with
$start = '2015-06-30 14:00';
$hours= 5;
//display the converted time
echo date('Y-m-d H:i',strtotime("+{$hours} hours",strtotime($start)));
The output is 2015-06-30 19:00