Calculation of time elapsed in PHP

Today I would like to write some code about calculating time elapsed in PHP. Especially if we want to know the elapsed time of inserted records (seconds, minutes, hours , days etc).

For example – Posted 1 週前、3 時間前、50 分間前、30秒間前。

Here is our function to calculate the time eclipse

I have included the comments in code so that you can be able to understand it. Let’s call our function to test.

PS. we have to care about our server timezone when we are dealing with Datetime functions

By Yuuma




tel. 06-6454-8833(平日 10:00~17:00)