I currently have php get the current time/date like so:
$now = date("Y-m-d H:m:s");
What id like to do is have a new variable $new_time
equal $now
+ $hours
. $hours
being an amount of hours ranging anywhere from 24-800.
Any suggestions?
I currently have php get the current time/date like so:
$now = date("Y-m-d H:m:s");
What id like to do is have a new variable $new_time
equal $now
+ $hours
. $hours
being an amount of hours ranging anywhere from 24-800.
Any suggestions?
I use following function to convert normal date-time value to mysql datetime format.
It converts datetime values like,
Hope this will help someone.
You can use strtotime() to achieve this:
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 usestrtotime(sprintf("+%d hours", $hours))
then.You can also use the unix style time to calculate:
Correct
You can use strtotime() to achieve this:
A combination of date() and strtotime() functions will do the trick.