I'm using timestamp in my php script to handle time in hours, minutes and seconds. Timestamps also record the date but I'm only using time 00:00:00
.
For instance I'm caluclate difference in time
$start = strtotime("12:00:00");
$end = strtotime("20:00:00");
$difference = $end - $start;
or dividing time
$divide = $difference/3;
Should I continue using timestamps for these operations or is there a time-specific function in php?
You could use mktime. You can call it that way:
the results are seconds, like time() and strtotime()
If timestamps suit you, then continue using them. There really isn't anything wrong with them (except the unix version of Y2K in 2038 when the timestamp will no longer fit in a 32bit int). PHP alternatively gives you another way to do time calculations with the DateTime class
There is no time specific standard function in php as far as I know, what you are doing is fine. However, it is fairly easy to do the calculation on your own.
Assuming the first date is later than the second this should work just fine
An example of how to do this with
DateTime
:Output: