PHP Adding 15 minutes to Time value
Your code doesn't work (parse) because you have an extra )
at the end that causes a Parse Error. Count, you have 2 (
and 3 )
. It would work fine if you fix that, but strtotime()
returns a timestamp, so to get a human readable time use date()
.
$selectedTime = "9:15:00";
$endTime = strtotime("+15 minutes", strtotime($selectedTime));
echo date('h:i:s', $endTime);
Get an editor that will syntax highlight and show unmatched parentheses, braces, etc.
To just do straight time without any TZ or DST and add 15 minutes (read zerkms comment):
$endTime = strtotime($selectedTime) + 900; //900 = 15 min X 60 sec
Still, the )
is the main issue here.
Adding 30 minutes to time formatted as H:i in PHP
$time = strtotime('10:00');
$startTime = date("H:i", strtotime('-30 minutes', $time));
$endTime = date("H:i", strtotime('+30 minutes', $time));
Adding minutes to date time in PHP
$minutes_to_add = 5;
$time = new DateTime('2011-11-17 05:05');
$time->add(new DateInterval('PT' . $minutes_to_add . 'M'));
$stamp = $time->format('Y-m-d H:i');
The ISO 8601 standard for duration is a string in the form of P{y}Y{m1}M{d}DT{h}H{m2}M{s}S
where the {*}
parts are replaced by a number value indicating how long the duration is.
For example, P1Y2DT5S
means 1 year, 2 days, and 5 seconds.
In the example above, we are providing PT5M
(or 5 minutes) to the DateInterval
constructor.
PHP Date Time Current Time Add Minutes
I think one of the best solutions and easiest is:
date("Y-m-d", strtotime("+30 minutes"))
Maybe it's not the most efficient but is one of the more understandable.
PHP check if date and time has passed 15 minutes
You can convert the date to a timestamp with strtotime
(which supports the MySQL date format) and then compare it to the current timestamp from time
.
$dbtimestamp = strtotime($datefromdb);
if (time() - $dbtimestamp > 15 * 60) {
// 15 mins has passed
}
To compare the dates, you can use date
to get the year/month/day from the timestamp and then compare them against the current date.
if (date("Y-m-d", $dbtimestamp) != date("Y-m-d")) {
// different date
}
Time calculation in php (add 10 hours)?
strtotime()
gives you a number back that represents a time in seconds. To increment it, add the corresponding number of seconds you want to add. 10 hours = 60*60*10 = 36000, so...
$date = date('h:i:s A', strtotime($today)+36000); // $today is today date
Edit: I had assumed you had a string time in $today - if you're just using the current time, even simpler:
$date = date('h:i:s A', time()+36000); // time() returns a time in seconds already
Add time to date time in php
You can try with strtotime
and date
function
$dateTime = '2016-09-08 21:00';
echo date( "Y-m-d h:i", strtotime( "2016-09-08 21:00 +4 hours" ) );
echo date( "Y-m-d H:i", strtotime( "2016-09-08 21:00 +1 hours 40 minutes" ) );
Related Topics
Align Text and Image Side to Side With Bootstrap
How to Get Username from Facebook Id
How to Get the MAC and the Ip Address of a Connected Client in PHP
How to Prevent a User from Directly Accessing My HTML Page by Writing Url
How to Get Last Insert Id in Sqlite
How to Set Current Date as Default Value of an Input
Telegram Bot Api: How to Send a Photo Using PHP
How to Get Values of Checkbox Array in Laravel 5
Clear the Form Field After Successful Submission of PHP Form
Redirect That Same Page from Where Id Is Coming
Showing Image Binary Data Using JavaScript
Retrieve MySQL Value from PHP for Radio Buttons
Preventing Direct Access to a PHP Page, Only Access If Redirected
How to Get Useful Error Messages in PHP