Hey all, just wondering how I can add 30 seconds on to this?
$time = date("m/d/Y h:i:s a", time());
Thankyou, again.
I wasn't sure how to do it because it is showing lots of different units of time, when I only want to add 30 seconds.
Hey all, just wondering how I can add 30 seconds on to this?
$time = date("m/d/Y h:i:s a", time());
Thankyou, again.
See mktime:
mktime (date("H"), date("i"), date("s") + 30)
http://www.php.net/manual/en/function.mktime.php
should do what you want.
If you're using php 5.3+, check out the DateTime::add operations or modify
, really much easier than this.
For example:
$startTime = new DateTime("09:00:00");
$endTime = new DateTime("19:00:00");
while($startTime < $endTime) {
$startTime->modify('+30 minutes'); // can be seconds, hours.. etc
echo $startTime->format('H:i:s')."<br>";
break;
}
$time = date("m/d/Y h:i:s", time());
$ts = strtotime($time);
$addtime = date("m/d/Y h:i:s", mktime(date("h", $ts),date("i", $ts),date("s", $ts)+30,date("Y", $ts),date("m", $ts),date("d", $ts));
Would be a more explained version of all of the above.
What about using strtotime? The code would then be:
strtotime( '+30 second' );
$time = date("m/d/Y h:i:s a", time() + 30);
//or
$time = date("m/d/Y h:i:s a", strtotime("+30 seconds"));