Reputation: 263
I have one table name (task), here i want take the count like how many registration happend in monthwise ,how how can do this ,
id name t_completed_on
1 Kani 2017-02-03 12:45:18
2 yuvi
3 Mahesh 2017-03-11 12:45:18
4 Rajesh
5 Kumar 2017-03-11 12:45:18
Here i am using this format date("Y-m-d h:i:s")
Bassed on my database this month registration 2.
Expected results:
This month registration : 2
I tried like this but i am getting the results 0, but actual results i need 2
SELECT count(*) as monthrecord FROM task WHERE MONTH (t_completed_on ) = MONTH( current_date ) -1 AND YEAR( t_completed_on ) = YEAR( current_date )
Upvotes: 1
Views: 1815
Reputation: 3520
Expected results:
This month registration : 2
SELECT count(*) as count
FROM my_table
WHERE t_completed_on > NOW() - INTERVAL 1 MONTH;
Upvotes: 3