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 Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
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 ?
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:
Month By Month Count
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?
Month By Month Count
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?
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.
Make MYSQL Delete Information Afetr 1 Month
I have users inputting info in a HTML form, which is uploaded to a MYSQL database; after 1 month I would like the info to be removed/deleted automatically, ie without having to have an administrator manually run a script; how do I do this?
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.
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?
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.
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.
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.
Increment By One Month
I have managed to obtain the latest date in a list of dates by using the following: SELECT date FROM mydata.data WHERE fund = "whatIwant" order by date desc limit 1 thing is, i actually want the latest date plus one month and then return this value. Any ideas?
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?
Current Month
How do you get the current month - 1 month? (so not a particular day, but the whole month)
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)) ) )
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");
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)
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; }
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?
Extracting Data From Last Month
I have written a query that will allow me to extract data from a table that will grab all records from last month - WHERE EXTRACT(MONTH FROM `DATE_TIME`) = (EXTRACT(MONTH FROM CURDATE()) ) This is all well and good, except for where I wish to run in January, because obviously my month-1 would equal 0.
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
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 ;)
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? .....
SQL To Summarize Data By Month
I am trying to create and insert statement that looks at data for a month and sums it by dept, area and month. I want to have it run automatically on the first of every month for data that is 60 days ago. How do I do that so that I get all the data for months that have 31 days?? I was going to go something like this reporting_date >= sysdate - 60 and reporting_date <= sysdate - 30. But I don't think that will get it all. My date in the new table is going to be YYYY-MM. Is there a way to take the month out of the sysdate and then subtract 2 from that and only look at the dates that have that specific month?
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.
Select Max Date Per Month
Using MySQL 4.1.5. I am pretty new to writing SQL queries so I am hoping someone can help me with this. I have the following data in a database. ID | Date | Value ------------------------ 2 | June 3 | 10 2 | June 15 | 5 2 | June 20 | 7 2 | July 7 | 10 3 | June 8 | 2 What I need is the value for the max date for each month for each ID. So, my result should look like the following: ID | Date | Value ------------------------ 2 | June 20 | 7 2 | July 7 | 10 3 | June 8 | 2 Can anyone give me any ideas on how I can go about doing this?
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.....
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
SQL-problem: First Monday Of The Month
I want to save events, which appear for example on every first and third monday of a month,in a database. My goal is to calculate the dates of these events.The Problem is, that I don't know how to save the parameters in a table. There are also events, that appear weekly or every second week.
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.
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
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)";
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?
Select Entrys Within Current Month
I wish to select rows from a table which is within the current month. It is to show 'current months transactions', i.e. give a gross value of the transactions. What is the best solution for doing this? Using SQL of course.
How To Get Data Based On The Month And Year??
"select month(str_to_date(fmonth,'%M')) from company where id=2;" (Query 1) The fmonth in company has values like 'March,October etc,...' this would give result as 4 for april (fmonth values in company table). i have another table which has values based on the date.(Transaction table) i want to fetch the values from the transaction table based on the date which is greater than the month of selected value fetched by the first query and of the year of current year.... i tried the query , "select *from transaction where date_format(transdate,'%Y %m') >= date_format(curdate(),'%Y %m');" This query returned the data which has a transdate >= 2006-10 i know that i have to combine the two query,but couldn't get those things.
Week Number In Specific Month
I have a problem regarding the week number in specific month..... i would like to get the week number in that certain month by just providing the date...... for example : 2007-10-07 - week 1 (oct) 2007-10-14 - week 2 (oct) but i want it to return me 1 when i provide (2007-10-07 to 2007-10-13) and return me 2 when i provide (2007-10-14o 2007-10-20) ..... and so on.... it is possible ?
Pulling All Data From Specific Month
I want to pull out all the data entries I've made for a specific month by using a $_GET method (archived.php?month=october). My field time rows look like "1161065143". How can I do a mysql_query for this? Here's what I have so far: mysql_query("SELECT * FROM entrynote WHERE time = '$date' SORTED BY time DESC
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;
Getting Year, Month, Day From A Timestamp Field.
I'm currently programming my own blog, however I've come into a minor problem with the way I want to display my archived posts. I want to display a list by year (2006, 2005, etc.) then a list of months for the specified year (nov, dec, etc.). I've searched the documentation and have been unable to find a sql command that retrieves parts of a timestamp. ie; timestamps are in YYYYMMDDHHMMSS format. I'm looking to extract the year, or month from that. ie; SELECT YEAR(timestamp) AS y FROM blog_posts GROUP BY y ORDER BY y DESC. or replace YEAR() with MONTH(). You get the idea. I did find a YEAR() command in the documention but it doesn't look to be what I'm looking for, since I was unable to find it's system commands MONTH() and DAY().
Update With Separate Month/year
In a table i have [stupidly] stored a date in separate month and year field, now i want to merge those fields and put them in a date field. have tried the following which puts the year in the date field - but how do i add the month aswell [the day should be set to 01] CODEupdate table set dateadd = str_to_date(yearadd,'%Y').
Select All Dates Since First Of Current Month
I'd like to write a query to select all records entered since the first of the current month (also, a query for all records entered during the previous month). A "date_in" field is being populated using the Now() function.
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']}'
To Find Days Per Month In A Date Range
How to find days per month in a date range using MySQL query? For example I have a start date - 04/28/2007 (mm/dd/Y) and end date 05/04/2007 , I have to find the days in each month that comes in the above date range In the above example the days in April are 3 and in may the days are 5 (I am using MySQL database,Please find a query that outputs the above result)
Display The Month Year's Dates That Have An Event
I am wanting to display the month year's dates that have an event from a database as a link. I forgotten how to do that. I know that it has something to do with SELECT. So can someone please tell me how I can do that?
|