im getting the time with this function :

time();

and im storaging this times in my database,

How can i calculate the difference of current and old date from the database ?

i need results like this : 1 min 10 sec ago

有帮助吗?

解决方案

If $time1 and $time2 are both generated by time() » UNIX_TIMESTAMP(), you can use:

$diff = $time1 - $time2;

The difference will be in seconds.

其他提示

Carbon is an exceedingly useful date/time library for PHP. It has a very handy "difference for humans" that will output that sort of difference string. https://github.com/briannesbitt/Carbon#api-humandiff

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top