Theres maybe two ways..
One is Javascript. Probably would be more accurate.
Or PHP
Which all i can think is to have a variable on when they entered. And one when they left which would have to be on another page. But if someone either left the site. Or closed the browser this would be inaccurate