Ciprian Kis Ciprian Kis - 1 year ago 192
MySQL Question

from INT to time in PHP

I'm out of ideas here..
in my DB table, I have all sorts of entries,
they all have a row with "start_time" and "duration" ..
in this situation, the only way I could've entered the values was:
10:00 is entered in the db as 1000,
23:00 is entered as 2300
the durations are 130 for 1 and a half hours .. or 20 for twenty minutes and so on.

they are entered just as you would expect them to be without any symbols separating the digits.
The problem is, I just can't add the numbers , I need to get the "end_time" calculated by adding the two values..

as an example, If i have an event starting at 1045 and it lasts 45 , I just need to echo 1130


Answer Source

I'll gladly change it to 0900

You can try following:

$timed = strtotime("+".$duration." minutes", strtotime($time));
echo date('Hi', $timed);

First you need to convert the time and add your duration. After that, you can echo it as desired.

For eg.

 $timed = strtotime("+130 minutes", strtotime("0900"));
 echo date('Hi', $timed); 

It will output


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download