So what I need to do is add 30 minutes to the following
date("Ymdhis");
I tried this
+strtotime("+30 minutes");
however it does not seem to like it. I wondering what the correct why to do this is.
strtotime("+30 minutes"); (which is an integer) to that string. date("Ymdhis", strtotime("+30 minutes"));
To add hours to a JavaScript Date object, use the setHours() method. Under that, get the current hours and 2 hours to it. JavaScript date setHours() method sets the hours for a specified date according to local time.
const date = new Date(); date. setDate(date. getDate() + 1); // ✅ 1 Day added console.
Your method of using strtotime
should work.
<?php echo date("Y/m/d H:i:s", strtotime("now")) . "\n"; echo date("Y/m/d H:i:s", strtotime("+30 minutes")); ?>
Output
2012/03/22 10:55:45 2012/03/22 11:25:45 // 30 minutes later
However your method of adding time probably isn't correct. The above will work to add 30 minutes to the current time. Suppose you want to add 30 minutes from a given time, $t
, then use strtotime
's second parameter, which is used as a base for the calculation of relative dates.
date("Y/m/d H:i:s", strtotime("+30 minutes", $t));
http://codepad.org/Z5yquF55
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