Add time to current time in php
I am trying to add 15minutes to the current time. I am using the following code: Show
But this still only prints the current time and not the current time + 15. I want it to add 15mins like so e.g. If the time is 12:30 the time after addition will be 12:45 Thanks.
peterh 11.1k15 gold badges80 silver badges102 bronze badges asked Nov 17, 2011 at 1:48
Duncan PalmerDuncan Palmer 2,83710 gold badges60 silver badges90 bronze badges Close, you want:
animuson♦ 52.7k28 gold badges139 silver badges145 bronze badges answered Nov 17, 2011 at 1:52
0 You could do:
answered Nov 17, 2011 at 1:51
Josh FoskettJosh Foskett 3,9955 gold badges31 silver badges35 bronze badges try this:
answered Nov 17, 2011 at 1:51
Book Of ZeusBook Of Zeus 49k18 gold badges174 silver badges169 bronze badges you can try this - answered Nov 17, 2011 at 1:52
Zoltan TothZoltan Toth 46.3k11 gold badges116 silver badges134 bronze badges In case anyone wants to make it work in Object-oriented way, here is the solution:
Requires PHP >= 5.3 answered Nov 17, 2011 at 1:58
RaptorRaptor 51.7k43 gold badges220 silver badges356 bronze badges 2 Home » How To Guides » PHP » How to add Days, Hours, Minutes, and Seconds to Datetime in PHP Here we’ll provide the simplest way to add days, minutes, hours and seconds to time using PHP. In PHP, using
$startTime = date("Y-m-d H:i:s");//display the starting time Using the above code you can add time to current time or any desire time. To sub-track use the same code except How to add time to date PHP?php $date=strtotime("tomorrow"); echo date("Y-m-d h:i:sa", $date) . "
"; $date=strtotime("next Sunday"); echo date("Y-m-d h:i:sa", $date) . " "; $date=strtotime("+3 Months"); echo date("Y-m-d h:i:sa", $date) . How to add hours in PHP?In your case to increase the current time by 10 hours: $date = date('h:i:s A', strtotime('+10 hours'));
How to get time from DateTime in PHP?php $date = "30-12-1899 9:25:52 AM"; $date = strtotime($date); echo date('H:i:s', $date); ?>
How do you add hours on Strtotime?You can use DateTime::modify to add time, but I would just do time()+10800 . Show activity on this post. $time = new DateTime("+ 3 hour"); $timestamp = $time->format('Y-M-d h:i:s a');
|