Hi
I got an string like ‘14:20’ from db. how can i do some math on it, for example add 50 min to it & get ‘15:10’ ?
Or add 2hour and get 16:20 ?
You can ask the DB to do this for you.
SELECT `time` + INTERVAL 50 MINUTE AS `time` FROM table
And if you still want to do it in PHP you might want to have a look at strtotime().
It’s a powerful function that even works with “sentences” like “last tuesday 2011” or “+1 day 50 minutes”.
I want to do it in php side. And i didnt see anything usefull in strtotime, it converts string to timestamp, i dont have any date here, only a time
Simple thing - specify any date or just leave it
$time = '14:20';
$old = strtotime('2011-01-01 '.$time);
$new = strtotime('+50 minutes', $old);
echo date('H:i', $new);
Or, shortened:
$time = '14:20';
echo date('H:i', strtotime('+50 minutes', strtotime('2011-01-01 '.$time)));
Both gives ‘15:10’ as result.
Also possible (no date given but still gives 15:10):
$time = '14:20';
echo date('H:i', strtotime('+50 minutes', strtotime($time)));
Thanx schuster