I have time like this 10:00:00 AM how to add + two hours with the time.
I have tried this:
$today = "10:00:00 am";
$starttime = "02:00:00";
$endtime = date("g:i:s a", $starttime+$today);
echo $endtime;
I have time like this 10:00:00 AM how to add + two hours with the time.
I have tried this:
$today = "10:00:00 am";
$starttime = "02:00:00";
$endtime = date("g:i:s a", $starttime+$today);
echo $endtime;
I vanilla PHP, object style using DataTime()
$date = new DateTime('10:00:00 AM');
$date->modify('+2 hours');
echo $date->format("g:i:s a");
Output:
12:00:00 pm
Or you can try lib Ouzo goodies, and do this in fluent way:
echo Clock::at('10:00:00 AM')->plusHours(2)->format("g:i:s a");
Output:
12:00:00 pm
Try this. If it works
$endtime = date("g:i:s a", strtotime('+2 hours', $starttime + $today));
Try this.
<?php
$today = "10:00:00 am";
$endtime = date("g:i:s a", strtotime("+2 hours",strtotime($today)));
echo $endtime;
?>
Try this:
$today = "10:00:00 am";
$starttime = "02:00:00";
$endtime = date("g:i:s a", strtotime("+2 hours", $starttime + $today));
echo $endtime;
More object oriented approach is using DateTime
and DateInterval
.
$start_date = new DateTime($result->start_date);
$start_date->add(new DateInterval('P' . (int)$probation_length . 'M'));
Adjust to fit your needs.