Search code examples
phpdate-arithmetic

How to calculate the time difference with two times?


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


Solution

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

    $diff = $time1 - $time2;
    

    The difference will be in seconds.