tags:

views:

36

answers:

1

In my DB I stored the time of the last page refresh in a TIME column. I want to compare the last page refresh to the current time now and find out how many 5 minuet periods have passed?

I was thinking take the last page refresh and subtract it from the current time then divide by 5. But I don't know about how things are formatted.

Help me please!

+1  A: 
SELECT *, FLOOR(((UNIX_TIMESTAMP()-time_field)/300)) AS periods FROM table

Im not sure for if UNIX_TIMESTAMP() returns correct timestamp, you will have to check it ;)
EDIT: checked it myself and its working great ;)

cichy
im assuming unix_timestamp is the current time and time field is the last page refresh? sorry kinda new to php >.<
Yes, in this query you should only change name of the table, and "time_field" to name of the column you have your last refresh, and it should work right away.
cichy
ok ill try it! thanks. but where does it tell me how many 5 min periods have passed?
I added name of the field where you will have 5 min periods counted, if you want to change it to 10 min etc, just change 300 to (60 * x) where x is minutes.
cichy
thank you i will try it.