title: How can I show when users were last active based on statistics?
body: <p>I have a database that stores the datetime from getdate() when they log into the system.</p>
  
  <p>I want to do a select that shows ones that have been active in the last 10mins as 'active now' and for all the rest, say how long ago they were active e.g. 3 days or 3hrs.</p>
  
  <p>I have no idea how to do the second part of that.</p>
  
  <p>This is what I have done to get the active users:</p>
  
  <pre><code>SELECT DISTINCT FirstName, LastName, 'Active now'
  FROM dbo.Users UP
  INNER JOIN Portal.dbo.UserStatistics US
  ON US.UserID = UP.UserID
  INNER JOIN Portal.dbo.Pages
  ON pages.id = US.PageID
  WHERE US.DateTimeLastUpdated &gt;= dateadd(minute, -5, getdate())
  </code></pre>