Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    MYSQL


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





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 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 !
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 Replies !
Display Period In Month Into Period In Year And Month
If i've below table,
NoOfMonth
------------
9
12
36
16
...

How to query to make it my result as follow,
NoOfMonth | Period_InYear | Period_InMonth
-------------------------------------------
9 | 0 | 9
12 | 1 | 0
36 | 3 | 0
16 | 1 | 4
...

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 !
Current Month
How do you get the current month - 1 month?

(so not a particular day, but the whole month)

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 !
Select Last Day Of Each Month
How do I query to get the last DATE of each month, though the DATE may not be the actual last day of the month.

Example Table ....

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 !
Easiest Way To Get Last Day Of A Given Month?
If I have the values &#3900;', &#3901;', &#3902;', etc, for all months in a year...what is the easiest way to determine the number of days in a given 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 !
FIRST Saturday Every Month
how do I know if some date corresponds to the FIRST monday of a month, or the SECOND Friday, etc?

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 !
Items Per Month Query
If I wanted to query the DB and get all itemid's = 111 that are marked "shipped" displayed by month how can I do this?

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 !
Display First Date Of The Month
Can any body help me in how to find out the first date of the month.

Eg:

Input:
12-Sep-2008

Ouput:
1-Sep-2008

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 !
Specific Month Selection
how to select the results for just cpecific month?

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 !
Statement Filter By Month
I have the following statement which works fine and returns the correct data for the day..

View Replies !
Only Select A Month In Date
How can i select rows that belong to a certain month, instead of by the whole date, when I have the date formatted in a Date type?

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 !
Why Do All Databases Rollback By One Month Itself?
I have 29 databases in mysql and used 1 year ago no problem. But one day I restart server. I shock very much because I found my all database rollback to 1 month ago....

View Replies !
Get People That Registered In This Month
I have a field called "registered_date" and i want to know who was registered in less than 30 days to the current day ....

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 !
Pulling Data From Last Month
I can't seem to to make the query call out last months highest clicks. I read the INTERVAL and subdate but don't know how to apply it.....

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 !
Comparing Month And Year From A Timestamp
select all artices where the month of the timestamp = $given_month AND year of the timestamp = $given_year.

To accomplish the above I tried (note: blog_date is the timestamp in the db):

SELECT * FROM blog_entries WHERE MONTH(blog_date) = 'january' AND YEAR(blog_date) = 2009.

The error I'm getting is unknown column MONTH(blog_date), etc....

View Replies !
Select Rows Only Created LAST MONTH
i want to run this below command, but only look at records from the previous month and where ACTIVE = 0

MYsql>
SELECT user,ROUND(AVG(overalldone), 1) AS average FROM data GROUP BY user ORDER BY average DESC;


View Replies !
Retrieve The 'month' From Datatype Date
is there any function that allows me to retrieve a particular information, say, the month, from the datatype 'date'?

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved