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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.