I currently have php returning the current date/time like so:
$now = date("Y-m-d H:m:s");
What I'd like to do is have a new variable $new_time
equal $now + $hours
, where $hours
is a number of hours ranging from 24 to 800.
Any suggestions?
3. If you want to add hours, minutes and second to a date simultaneously, you can use this formula =A2+TIME(23,23,34), this means to add 23 hours, 23 minutes and 34 seconds to a date cell.
To add hours in the current date-time, we use AddHours() method of DateTime class in C#. Syntax: DateTime DateTime. AddHours(double);
To add hours to a Date in JavaScript:function addHours(numOfHours, date = new Date()) { date.
Example 1: PHP Add Hours to DateTime$newDate = date('Y-m-d H:i:s', strtotime($date. ' + 3 hours')); echo $newDate; ?>
You may use something like the strtotime()
function to add something to the current timestamp. $new_time = date("Y-m-d H:i:s", strtotime('+5 hours'))
.
If you need variables in the function, you must use double quotes then like strtotime("+{$hours} hours")
, however better you use strtotime(sprintf("+%d hours", $hours))
then.
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