Reputation: 600
I have value 10:00:00 in my mor_start which is of type time in mysql database i want it to increment by 15 minutes.
$tim=$values['mor_start'];
$date = date('H:i:s', strtotime($tim));
echo $date;
the above code displays 10:00:00
but when i try to increment the time by the following code i get error : Notice: A non well formed numeric value encountered
$tim=$values['mor_start'];
$date = date('H:i:s', strtotime("+15 minutes",$tim));
echo $date;
Upvotes: 0
Views: 1106
Reputation: 43552
Calling strtotime()
multiple times is a little overkill. Code with DateTime extension is a faster example (and ofc more beautiful), like this demo:
echo date_create('10:00:00')->modify('+15 minute')->format('H:i:s');
Test this demo on your localhost and see the difference. My result on 1e6
loops is:
add15min_v1() has looped 1000000x times in 23.47sec.
add15min_v2() has looped 1000000x times in 6.81sec.
Upvotes: 1
Reputation: 3329
try this
$date = date('H:i:s', strtotime("+15 minutes", strtotime($tim)));
http://php.net/manual/en/function.strtotime.php
Upvotes: 0
Reputation: 1541
As Mark Baker said (he should deserve the answer) one correct solution is replace the calculation by this :
strtotime("+15 minutes",strtotime($tim)));
Upvotes: 1
Reputation: 3163
$tim=$values['mor_start'];
$date = date("H:i:s", strtotime("+15 minutes",strtotime($tim)));
echo $date;
This should work.
Upvotes: -1