How can I add 30 seconds to this time?
$time = date("m/d/Y h:i:s a", time());
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.
php $time = "01:30:00"; list ($hr, $min, $sec) = explode(':',$time); $time = 0; $time = (((int)$hr) * 60 * 60) + (((int)$min) * 60) + ((int)$sec); echo $time; ?>
To add minutes to a datetime you can use DATE_ADD() function from MySQL. In PHP, you can use strtotime(). select date_add(yourColumnName,interval 30 minute) from yourTableName; To use the above syntax, let us create a table.
The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.
php $next_due_date = date('y-m-d',strtotime('+30 days',strtotime('echo $userRow3["due_date"]'))) .
$time = date("m/d/Y h:i:s a", time() + 30);
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;
}
What about using strtotime? The code would then be:
strtotime( '+30 second' );
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