I have this variable:
$timestamp = strftime("%Y-%m-%d %h:%M:%S %a", time ());
I simply want to add three hours and echo it out.
I have seen the way where you can do the 60 * 60 * 3 method or the hard code "+ 3 hours" where it understands the words.
What is the best way of getting this result?
PHP strtotime() Function "<br>"); echo(strtotime("+5 hours") . "<br>"); echo(strtotime("+1 week") .
To add 24 hours to a Unix timestamp we can use any of these methods: Method 1: Convert 24 hours to seconds and add the result to current Unix time. echo time() + (24*60*60);
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.
Just add seconds to add hours:
strtotime($your_date)+2*60*60
This will add two hours in your date.
i always do like this
$current_time = date('Y-m-d H:i:s');
$new_time = strtotime($current_time . "+3hours");
echo $new_time;
or
$new_time = mktime(date('H')+3, 0, 0, date('m'), date('d'), date('Y'));
$new_time = date('Y-m-d H:i:s', $new_time);
echo $new_time;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With