문제

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