Add 'X' Number of Hours to Date

Add 'x' number of hours to date

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.

How to add hours to a Date object?

JavaScript itself has terrible Date/Time API's. Nonetheless, you can do this in pure JavaScript:

Date.prototype.addHours = function(h) {
this.setTime(this.getTime() + (h*60*60*1000));
return this;

PHP Add one hour to current date time

$my_date_time = date("Y-m-d H:i:s", strtotime("+1 hours"))

Construct a new date by adding X number of hours (Unix Shell)

You can use:

# your date variable
dt=$(date -d '2016-08-15 11:10:15')

# add 1 hour to $dt now
date -d "$dt +1 hour"
Mon Aug 15 12:10:15 EDT 2016

PHP Add 4 hours to date

Does this work?

$date = $dates[0] < $dates[1] ? $dates[1] : $dates[0];
$new_date = date("Y-m-d H:i:s", strtotime('+4 hours', strtotime($date)));
echo $date;
echo "<br/>". $new_date;

You were passing $date AS the second argument of strtotime, and it's not a UNIX timestamp (as you said). So with strtotime again, you should convert it in a UNIX timestamp, and then pass it to strtotime.

Javascript add hours to time

for adding hours, use setHours :