Page 1 of 1

Subtracting time and whatnot.

Posted: Mon Mar 03, 2008 11:15 am
by Mightywayne
So I'm making a script to tell when the person's last action on the game was, and I don't want to just put it as "Last action was at blah blah.", I want to be like "It was 2 hours, 3 minutes ago." or something like.

Basically what will happen is their last action goes into the DB, then I use date(); to "subtract" the other time from now. Unfortunately I have no idea how to go about this, and the date(); talk on PHP website is confusing as usual.

Re: Subtracting time and whatnot.

Posted: Mon Mar 03, 2008 12:44 pm
by Christopher
Use Unix timestamps and subtract the current time from the previous. That will give you the elapsed time in seconds. Then divide by 60*60 for hours and the remainder by 60 for seconds.

Re: Subtracting time and whatnot.

Posted: Mon Mar 03, 2008 1:11 pm
by Mightywayne
Perfection. Thanks.