How to add 1 hour in php time?
I have a time to which I want to add an hour: Show
I've tried:
But none of the above work.
Dharman♦ 28k21 gold badges75 silver badges127 bronze badges asked Dec 18, 2011 at 13:43 1 Worked for me..
Explanation:
answered Dec 18, 2011 at 13:46
paulcol.paulcol. 2,7211 gold badge20 silver badges18 bronze badges 2 You can do like this
answered Jul 2, 2014 at 9:21
Azam AlviAzam Alvi 6,6087 gold badges60 silver badges84 bronze badges 1
Check PHP manual for strtotime(), strftime() and date() for details. BTW, in your initial code, you need to add some quotes otherwise you will get PHP syntax errors:
answered Dec 18, 2011 at 13:49
Frosty ZFrosty Z 21.6k11 gold badges81 silver badges110 bronze badges try this it is worked for me.
answered Mar 25, 2016 at 6:53
Mayank VadiyaMayank Vadiya 1,4172 gold badges20 silver badges31 bronze badges 3 2020 UpdateIt is weird that no one has suggested the OOP way:
OR
OR
Extract it in string with format:
Dharman♦ 28k21 gold badges75 silver badges127 bronze badges answered Dec 16, 2019 at 10:38
Abhay MauryaAbhay Maurya 11k6 gold badges44 silver badges59 bronze badges Simple and smart solution:
answered Dec 1, 2015 at 21:50
You can try this code:
Hamed B 1391 silver badge11 bronze badges answered Apr 6, 2016 at 9:12
I had a similar problem and the fix was to say “hours” instead of “hour”. answered May 26 at 16:27
Beware of adding 3600!! may be a problem on day change because of unix timestamp format uses moth before day. e.g. 2012-03-02 23:33:33 would become 2014-01-13 13:00:00 by adding 3600 better use mktime and date functions they can handle this and things like adding 25 hours etc. answered Feb 11, 2014 at 16:17
2021 Update Worked for me..
Output:
answered Mar 20, 2021 at 6:13
How to add hours in php time?In your case to increase the current time by 10 hours: $date = date('h:i:s A', strtotime('+10 hours'));
How to add time with another time in php?Example 1: PHP Add Minutes to Time
$newDate = date('H:i:s', strtotime($date. ' +10 minutes')); echo $newDate; ?>
How to add hours and minutes to time in php?PHP | DateTime add() Function
The DateTime::add() function is an inbuilt function in PHP which is used to add an amount of time (days, months, years, hours, minutes and seconds) to the given DateTime object.
What does time () do in PHP?The time() function returns the current time in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
|