How can I write a query to get a list of users who have registered in the last 24 hours?
It seems to me that you aren't doing anything wrong; it's just that the object you will get back from db_query() in your case is not something you can use as is.

Invoke -&gt;fetchField() method after db_query() so that Drupal's DB API returns you one single value.

Use this:

$users_registered = db_query("SELECT COUNT(DISTINCT u.uid) FROM {users} u WHERE u.created &gt;= :timestamp AND u.uid &gt; 0", array(':timestamp' =&gt; (REQUEST_TIME - 86400)));


Also, use REQUEST_TIME constant to get current timestamp.

Hope this helps.