Reputation: 2229
On my site user registration date stored as timestamp in varchar(20) column. I want to count how many users registered today, i written query:
SELECT COUNT(*) as count FROM `users` WHERE `user_group` = 7 AND `reg_date > 1368993600
1368993600 - today 0:00. This query return me count of all users instead of count registered today. I edited query:
SELECT COUNT(*) as count FROM `users` WHERE `user_group` = 7 AND CAST(`reg_date` AS SIGNED) > 1368993600
But it still not working... How I can count users registered today?
Upvotes: 0
Views: 126
Reputation: 3751
You are deducting something wrong and your error is somewhere else. See this SQL Fiddle, using the same data structure you are mentioning and using your first query without CAST
, and you will see it's working fine. Only 3 rows are returned and are the ones that have a value greater than 1368993600.
Upvotes: 1
Reputation: 204766
SELECT COUNT(*) as count
FROM `users`
WHERE `user_group` = 7
AND `reg_date` - timestamp(curdate()) >= 0
Upvotes: 1