thaxroads Posted February 2, 2009 Share Posted February 2, 2009 I have a cms site I'm making and I want to add a section in the admin area where it shows how many users joined: TODAY YESTERDAY THIS MONTH LAST MONTH THIS YEAR LAST YEAR The queries I have so far: $query="SELECT count(*) FROM users WHERE joindate=now()-INTERVAL 24 HOUR"; // TODAY $query="SELECT count(*) FROM users WHERE joindate=now()-INTERVAL 1 DAY"; // YESTERDAY $query="SELECT count(*) FROM users WHERE YEAR(joindate)=YEAR(now()) AND MONTH(joindate)=MONTH(now())"; $query="SELECT count(*) FROM users WHERE YEAR(joindate)=YEAR(now()-INTERVAL 1 MONTH) AND MONTH(joindate)=MONTH(now()-INTERVAL 1 MONTH)"; $query="SELECT count(*) FROM users WHERE YEAR(joindate)=YEAR(now())"; $query="SELECT count(*) FROM users WHERE YEAR(joindate)=YEAR(now()-INTERVAL 1 YEAR)"; of course the first two codes which are today & yesterday queries do not work ... the dates are in the MySQL database in this format: 0000-00-00 00:00:00 ... can someone help me out with the correct queries I'm looking for .. Any help would be appreciated Thanks Quote Link to comment https://forums.phpfreaks.com/topic/143470-solved-date-queries/ Share on other sites More sharing options...
Chicken Little Posted February 2, 2009 Share Posted February 2, 2009 Try using CURDATE, this should get you yesterday SELECT * FROM users WHERE DATE( joindate ) <= DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ) ORDER BY joindate DESC Quote Link to comment https://forums.phpfreaks.com/topic/143470-solved-date-queries/#findComment-752658 Share on other sites More sharing options...
thaxroads Posted February 2, 2009 Author Share Posted February 2, 2009 Try using CURDATE, this should get you yesterday SELECT * FROM users WHERE DATE( joindate ) <= DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ) ORDER BY joindate DESC Thanks ... this is what I came up with after your input about CURDATE(): $query="SELECT count(*) FROM users WHERE DATE(joindate)=CURDATE()"; //USER JOINED TODAY $query="SELECT count(*) FROM users WHERE DATE(joindate)=DATE_ADD(CURDATE(), INTERVAL -1 DAY)"; // USERS JOINED YESTERDAY Works like a charm! Thanks Again!! Quote Link to comment https://forums.phpfreaks.com/topic/143470-solved-date-queries/#findComment-752745 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.