Month By Month Count Of Records
I need to generate record counts for each month in a year, just one year at a time, but a full year at a glance. I am thinking 12 hits to the DB is perhaps not the most idea way to do it, is there a way to rip this out in one go?
View Complete Forum Thread with Replies
Related Forum Messages:
Mysql Is Giving The Previous Month, Not This Month, Strange!
PHP Code: $myquery = @mysql_query("select year(sendon) as yr, month(sendon) as mth, count(*) as hits from ebook_user group by yr, mth"); while ($myrow = mysql_fetch_array($myquery)) { $mymonth = $myrow['mth']; $myyear = $myrow['yr']; $myhits = $myrow['hits']; print '<td bgcolor="#E7E7E5">'.date("M", mktime(0, 0, 0, $mymonth, 0, $myyear)).' '.$myyear.' </td><td bgcolor="#E7E7E5"> '.$myhits.'</td>' } The above code is printing the previous month instead of current month ... can any one help?
View Replies !
Collecting Month By Month Results
does anyone have thoughts on how to do queries that produce date bins? I do things like DATE_FORMAT( created_time , '%M %Y' ) AS date and then group by date thing is that when there is nothing in a particular month, no row is returned ... So a query like this: Code:
View Replies !
Number Of Records Per-Month
i have got a script that log all downloads (daily) in a database. I would like to know how to query that database, to get the number of records per month. My records look like this date ip 2006-01-01 200.1.157.11 2006-01-01 192.168.10.3 2006-02-05 198.10.10.2 etc needed output 01 2 02 1
View Replies !
Count The Hits For Week And Month In One Query?
I have this query to count the amount of total clicks for a whole week, but i would also like to know the total amount of clicks for the whole month. Is it possible to do both of them with one query? Or do i really need to make 2 seperate querys for that? SELECT date FROM clicks WHERE date >= '$timestamps[0]' and date <= '$timestamps[6]' AND link_id = '{$row['ad_linkid']}'
View Replies !
Retrieving Months And News Count From That Month
I'm creating a news archive page. Here is a trimmed down version of my news table: news_id author_id title maintext date_added (datetime) What I want to do in one query is get a list of all the months in a given year and a count of how many news stories were added in each month. Off the top of my head I could just think of selecting distinct month from date_added and counting the news items in that month and given year. Perhaps there is a better way though as I realise the distinct function isn't very efficient.
View Replies !
Count And Group By Month In 1 Query For A Date Range?
I have a table that has employees work history on it. Basically the only thing I am worried about is the start and end date. My boss wants a report that charts out the quantity of workers for the past 12 months group by the month. For example Employee--Start Date--End Date Charles-----2008-6-3---2009-2-1 Vicky-------2009-1-1---Present So in this case there would be a quantity of 1 from June 08 to December 08. Then their would be a quantity of 2 from Jan 09 to Feb 09. And Vicky would also be counted for March since she is still working. I can do this by creating PHP functions and putting it all together, but I was just wondering if there was a way to do this all in 1 query.
View Replies !
Selecting Records Between Two Dates Occurring In Certain Month Of A Year
I have trouble with querying events for my calendar. It consists of as simple fields as these (only relevant fields to my question): event_id (INT10) event_date_begin (DATE) event_date_end (DATE) now, an example row: event_date_begin has a value of 2008-12-28, event_date_end has a value of 2009-01-04 How can I retrieve this row, knowing only the current month and year, say I want to display all the events in my calendar happening / continuing in January 2009 (1/2009). So this query should be able to fetch my example row, because the event is still occurring in January (ending date in 2009-01-04). I can display one month / year at a time, so the query always has those, for example 01, 2009. I think what I need, is some kind of "function" to check, if certain month and year exist between those two date fields..? The closest I've got so far is: 'SELECT event_id, event_date_begin, event_date_end FROM events WHERE 12 BETWEEN MONTH(event_date_begin) AND MONTH(event_date_end) OR MONTH(event_date_begin) = 12 ORDER BY event_id ASC'; This query returns all the necessary rows, also if the event continues to the next month, but when the year changes it stops working correctly..
View Replies !
Different Month
I have a table that has a column containing date and time information with format of 0000-00-00 00:00:00, I want to know how to write query to get rows that are in 2006 Jan, Feb, Mar, ..., return information on a monthly period. I use PHP to allow users to input the 2006-01, 2006-02, in my code, I check if value is 2006-01, then I set two variables to '2006-01-01' and '2006-01-31'; if the value is 2006-02, then set the values to '2006-02-01' and '2006-02-28'. But I hope there is better way instead of writing if condition one by one.
View Replies !
How To Add One Month To Now()?
Within my PHP5 application I need to set an expiry date when inserting/updating into the MySQL database - but honestly I've got no clue how... Specifically - it needs to be one month from the day of the insert/update (thus one month past Now()) Currently I've got the following working fine: UPDATE item SET expdate=Now() WHERE pid=1; Obviously this set the expdate to the current date, I've tried doing Now()+1 (didn't work), was looking into ADDDATE (couldn't get it to work), etc. How, in MySQL, can I add 1 month to Now()?
View Replies !
Get The Next Month , Or The Month Before
I need to get next day/month, based on the current date. Cannot find functions for dates range. today : 20090311 need to get the next day: 20090312 today is 20091231 need to return 20100101 SELECT ADDDATE( current_date, INTERVAL 1 DAY); today : 20090311 need to return day before: 20090310 today is 20100101 need to return 20091231 SELECT ADDDATE( current_date, INTERVAL -1 DAY); dates range today : 20090311 need to return strdate: 20090401 enddate: 20090430 today is 20091212 need to return strdate: 20100101 enddate: 20100131 today : 20090311 need to return strdate: 20090201 enddate: 20090228 today is 20100105 need to return strdate: 20091201 enddate: 20091231
View Replies !
Last Month Value?
Is there a simple query to return the previous month range? For instance, on October, I would like to run a report for the month of September. So, I would just like to get the date range from September 1st 2004 to September 30th 2004. This would be helpful as every month's number of days varies and also in case, it is a leap year.
View Replies !
MONTH And DAY
I have a table containing a Date field Birthday. I'd like to find all the birthdays today. In Access: select * from Alumni where (month([Birthdate])=2) and (day([Birthdate])=1); This errors out in MySql. I've tried month(Birthdate), month('Birthdate'), month[Birthdate], etc. - all fail.
View Replies !
Last Month
I was wondering if people had a better way of doing this, I am just trying to set an SQL way of doing a time span for last month. Below is an example of how I would use this. date between Dateadd(dd,-Day(getdate())+1,DateAdd(m,-1,GetDate())) and Dateadd(dd,-Day(getdate()),DateAdd(m,0,GetDate())) This will do it, but I was wondering if there is an easier way?
View Replies !
MySQL In 1 Month
I do some website design here and there occasionally for a few clients and I've got a new one that wants a database with their website that will display pricelists displayed for their products and they want the ability to have individual logins for their customers. I'm more of a designer than a programmer and I've never really done anything complex with a database before, and certainly nothing with MySQL. I had someone who I thought was going to do the database part with me, but he no longer wants to do it. So I was wondering if its possible to learn MySQL in a motnh or so well enough to allow it to interface with a website and do what this client is suggesting? Does anyone have any helpful tips, tutorials, books etc that would help me do this fairly quickly? Being a full time college student taking summer classes I already feel swamped! But I want to try to get this working if possible.
View Replies !
Last Month Of Data
I am trying to limit my query to the last month of data. Below is the limiter that I have used. The query is accepted by the server, and returns data, but does not limit the data. Any suggestions as to how to correct this? where issueddate > date_sub(current_date,interval 1 month)
View Replies !
Order By Month
How can one "ORDER BY month"? I wish to select a heap of distinct months and list them in the correct order eg: January, February, March etc... I experimented with the month(month) function but to no avail. I currently have the month stored as 'January' for example using PHP date format date("F");
View Replies !
How To Get The Last Saturday Of Month?
I need to query on the date in one of my table but I need to calculate the last saturday of month first. How do I do that in SQL statement? Specifically, How do I find the last saturday of month given the date (as SQL parameter) in SQL statement in MySQL?
View Replies !
This Or Next Month From Today
I want to select records which go from a certain date, until the end of next month. I struggled with DATE_ADD, but I think it gets more complicated than needed. This is what I made: SELECT * FROM table WHERE cat='1' AND ( record_date >= $test_date ) AND ( ( YEAR(record_date) = YEAR($test_date) AND ( MONTH(record_date) = MONTH($test_date) OR MONTH(record_date) = MONTH(DATE_ADD($test_date,INTERVAL 1 MONTH)) ) ) OR ( YEAR(record_date) = (YEAR($testdatum) + 1) AND MONTH(record_date) = MONTH(DATE_ADD($test_date,INTERVAL 1 MONTH)) ) )
View Replies !
How To The Numeric Value Of The Month?
i'm a table in which i store the month as full month i.e March,October And i'm going to fetch the data from other table bases on the month value gets from the first table. I'm a date field in the second table which i'm going to check the rows for greater than the fetched month.. How i can handle this. If i can get the values as 10,4 for October,March respectively then i can easily get the data from the other table.
View Replies !
Get Month From Database?
How can I query a database to get all entries from the month of July 08 using get from the browser bar? $SQL = "SELECT field1, field2 from dbtable WHERE the_date=".$_GET['july_string_from_get'];
View Replies !
Update Month + 1
I have a table with some data fields. I wish to update the table in order to have the data entries as new_data= old_data + 1 month.
View Replies !
Birthday Query Per Month
I want to output all the birthday celebrants for every month. YYYY-MM-DD is the format is my birthday. Not just the present month birthday celebrant but, per month. I try to use Select * from tblSample where birthday between '' and ''; But no success for i don't have the start date and end date of every month.
View Replies !
Date Format With Month Name
if it is possible to insert into a mySQL db a date format formatted like so: 11-Oct-06. I would like to save myself any tedious string processing tasks (I know I could convert it with PHP...).
View Replies !
Determine Previous Month
basically I need to display a list of "unpaid" statements for the previous Month, no matter what day the search/request is made on. I know MySQL has the DATE_SUB function where I can subtract 1 Month from the current date, but will that subtract the date exactly 1 month to the day ? Or will it simply give me the Month as I need ? What happens if the search takes place on the 31st of a month (for example: July), yet the previous month only has 30 days (June). Will it roll back to the previous month correctly or think that the date is 31st June or try to roll back further until it finds another month which has 31 days ?
View Replies !
Rows In Past Month
I know I'm not writing this SQL command properly, please correct it for me. sql Code: Original - sql Code SELECT newsid,title,posted,content FROM `news` WHERE NOW() - `posted` < 2678400 SELECT newsid,title,posted,content FROM `news` WHERE NOW() - `posted` < 2678400
View Replies !
Current MONTH And YEAR
Having an event-calendar table, and an attribute event_date, How can i retrieve the events of the current month and current year based on that field? .....
View Replies !
Display Month As April Instead Of 4
I am trying to return the current month, by the month's actual name rather than the number of month. SELECT MONTH(CURRENT_DATE); I want to see April instead of 4. I was thinking I need to add DATE_FORMAT but I'm not sure what the syntax should be.
View Replies !
Return Groups For Each Month
I would like to return monthly reports with a single query.For example: January 15 Purchases 5 Refunds 6 Exchanges February 20 Purchases 4 Refunds 2 Exchanges The above data has about 60 records. The query has to group by month and then again by transaction type. Here is what the record would look like TransactionID - primary key TransactionDate - Date Transactiontype - integer
View Replies !
Filtering The Birthdays By Month
I'm working on a procedure about the birthdays of the employees, but I'm having a hard time making it appear in the browser.. I'm not sure about the right query in filtering the b-days by month.
View Replies !
Selecting Average Per Month
********************** *PDATE **** Price * ********************** *2008-12-03** 22 * ********************** *2008-12-01** 36 * ********************** *2008-12-09** 54 * ********************** *2008-11-05** 21 * ********************** *2008-11-15** 22 * ********************** ******************** *Month **** AVG * ******************** *December ** 22 * ******************** *November ** 36 * ********************
View Replies !
MONTH(TODAY) Commands
I have a line in mySQL that I need to select anyone whose birthday is today. The field name is BIRTHDATE and is shown in the database as mm/dd/yyyy. How do I select the current month and day so that I can use someone's birthday from 8/22/1970 or 8/22/1975 or 8/22/1950...etc. I was instructed to use this, but it's not working... mySQL="SELECT * from EE_info where MONTH(TODAY)=MONTH(BIRTHDATE) and DAY(TODAY)=DAY(BIRTHDATE)";
View Replies !
Dates, Month And Year
I want to query by month and year a field of date type: eg. : 2005-08-18 so i will receive 2005 or 2004 or 2006 and the months 01, 02 03 ... How this query will be? select * from table substr(date, 0, 4) //for year select * from table substr(date, 6, 2) //for month
View Replies !
Order By Month Added (PHP)
I want to pull information on 'archives' from a database - I need to show each month that content was added and how many posts there are. E.g. October, 05: 1 posts September, 05: 5 posts August, 05: 4 posts ..and so on. I thought I'd figured it out before and got it working but I must have changed something because now I get the months times by amount of posts: # October, 05 # September, 05 # September, 05 # September, 05 # September, 05 # September, 05 # August, 05 # August, 05 # August, 05 # August, 05 ..and so on. The month is stored in a 'normal' date format (YYYY-MM-DD). Any help would be appreciated, ask if you need more info from me. I don't have the original code I was working on with me so please don't ask ;)
View Replies !
SELECTING 1st(Last) Wednesday Of Every Month Etc
I have written what I consider a lengthy script for what would seem to be a trival task. I would first like to examine the MySQL portion later I can post in PHP to examine that portion. I Have tried to comment the PHP the best I could to make it readable to people whom do not know PHP. The purpose of posting this is to A. Find out is there an easier way. B. If not share it with SitePoint. Here is the input Form - nothing Special <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="Date"> Select the <select name="rec" type="text"> <option value="1">1st</option> <option value="2">2nd</option> <option value="3">3rd</option> <option value="4">4th</option> <option value="5">last</option> </select><select name="rec2" type="text"> <option value="0">Day</option> <option value="1">Sun</option> <option value="2">Mon</option> <option value="3">Tues</option> <option value="4">Wed</option> <option value="5">Thur</option> <option value="6">Fri</option> <option value="7">Sat</option> </select> of <select name="month"> <option value="1">Jan</option> <option value="2">Feb</option> <option value="3">Mar</option> <option value="4">Apr</option> <option value="5">May</option> <option value="6">June</option> <option value="7">July</option> <option value="8">Aug</option> <option value="9">Sept</option> <option value="10">Oct</option> <option value="11">Nov</option> <option value="12">Dec</option> </select> in <input type="text" name="year" maxlength="4" /> <input type="submit" value="Get Date" name="GetDate" /></form> Here is the Processing PHP and MySQL PHP if (isset($_POST['GetDate'])) { //Assign Variables $month = $_POST['month']; $year = $_POST['year']; $rec = $_POST['rec']; $rec2 = $_POST['rec2']; if ($rec == 5) { // Select The Last Date of the Month $query = mysql_query("SELECT LAST_DAY('$year-$month-01')"); $row = mysql_fetch_row($query); $LastDay = $row[0]; $query = mysql_query("SELECT DAYOFWEEK('$LastDay')"); } else $query = mysql_query("SELECT DAYOFWEEK('$year-$month-01')"); $row = mysql_fetch_row($query); $DayofWeek = $row[0]; //Numberic First Day of the Week if ($rec == 5) $Vary = $DayofWeek - $rec2; // Subtract The Days else $Vary = $rec2 - $DayofWeek; // Add Days until the Selected day of the week occurs if ($rec2 == 0) // If Day is Selected $Vary = $rec2; // Vary = 0 if ($Vary < 0 && $rec2 != 0) $Vary = $Vary + 7; // If Day of the Week has Passed Then Figure how many days until next week. if ($rec != 5) $Vary = $Vary + (7 * $rec) - 7; //Calculate Numbers of Days according to which week was selected. // Add the Proper Days to Month and Year if ($rec == 5) $query = mysql_query("SELECT DATE_SUB('$LastDay', INTERVAL $Vary DAY)"); else $query = mysql_query("SELECT DATE_ADD('$year-$month-01', INTERVAL $Vary DAY)"); $row = mysql_fetch_row($query); $resource = $row[0]; echo $resource; }
View Replies !
Grouping A Result Set By Month
as the title suggests, i want to group a result set by the month they were created. i have a `time_created` header. this is how i am doing it, it works but it seems inefficient, i was hoping you guys could help me come up with a prettier way of doing this: SELECT COUNT(*) as numResults, CONCAT(MONTH(time_created), YEAR(time_created)) as groupName FROM filesGROUP BY CONCAT(MONTH(time_created), YEAR(time_created)) i am afraid of this because it uses string concatenation in the GROUP BY which seems like it would require analysis on EVERY row--of which there could be thousands of results. is there any way to do this while still using the indexes to preserve speed?
View Replies !
|