kamal213 Posted June 6, 2011 Share Posted June 6, 2011 Hi Guyz, I have a customer statistics page on my PHP customer management system, which give information of how many customers are added on each day using the SQL COUNT(*). I would like to calculate the total number of customers added each week. Please I would really apprectiate your help, ideas and suggestions, let me know if you need to see some code for more info. Thanks alot Quote Link to comment Share on other sites More sharing options...
WebStyles Posted June 6, 2011 Share Posted June 6, 2011 same thing, use COUNT(*) combined with `date` BETWEEN '$starDate' AND '$endDate' Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted June 6, 2011 Share Posted June 6, 2011 Something like this: select count(*) total, date_format(date_column, '%U') week from stats group by date_format(date_column, '%U'); Quote Link to comment Share on other sites More sharing options...
kamal213 Posted June 6, 2011 Author Share Posted June 6, 2011 Thanks for getting back to me webstyle Great point! Would I be on the right track if I said $starDate = strtotime("$day-$month-$year -7 day"); and $endDate = strtotime("$day-$month-$year +7 day"); Quote Link to comment Share on other sites More sharing options...
kamal213 Posted June 6, 2011 Author Share Posted June 6, 2011 Thanks The Little Guy, are total, date_format, and date_column fuctions of sql or its just an illustration? soz, you can tell i dnt kno much bout sql lol! Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted June 6, 2011 Share Posted June 6, 2011 they are all functions except for for: date_column, total, week date_column = the column name of your date total = renames count(*) to total week = renames date_format(date_column, '%U') to week Quote Link to comment Share on other sites More sharing options...
kamal213 Posted June 6, 2011 Author Share Posted June 6, 2011 Guru!! It worked TLG! Genius Quote Link to comment Share on other sites More sharing options...
kamal213 Posted June 6, 2011 Author Share Posted June 6, 2011 Jst 4 future ref TLG, Could do you know what the %U stands for. Thanks Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted June 6, 2011 Share Posted June 6, 2011 Could do you know what the %U stands for. I was waiting for that question The %U stands for the week number 00-53 (54 weeks in a year) using Sunday as the first day of the week. Full list: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format Quote Link to comment Share on other sites More sharing options...
kamal213 Posted June 6, 2011 Author Share Posted June 6, 2011 Interesting! You learn somethang new everyday. Thanks for that TLG can I add you as a buddy? Quote Link to comment 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.