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.





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 Complete Forum Thread with Replies

Related Forum Messages:
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 !
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 !
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 !
Selecting All Rows By Year And Month
I have a lot of records for invoices. Each record has a field with DATE datatype, so YYYY-MM-DD format is set.

I`d like to get all invoices from 2008-10 period. What is the best approach for that?

I see solutions like this:

SELECT *
FROM invoices
WHERE DATE_FORMAT(date,'%Y-%m') = '2008-10';

or:
SELECT *
FROM invoices
WHERE YEAR(date) = 2008 AND MONTH(date) = 10;

or add two new additional cols to table invoices (month and year). I need good performance for that because this records is really quite a lot and getting more each month.

View Replies !
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().

View Replies !
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.


View Replies !
Format Datetime (day, Month Date And Year)
How to format this datetime format

2003-11-09 08:58:59

to

Sun, November 9 2003 8:58am

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 !
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 !
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 !
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 !
Display Result With Specific Month
I have a table with a column "date" with value eg 1/1/2009 where by month/day/year.

I want to create a stored procedure that will produce each months result....and maybe put it into another newly created table?

but how do i select those rows that are from a specific month for example? i have problem specific the months from the date 1/1/2009

each table only contains specific year results. so if the table is for 2009, there won't be a 1/1/2008 result in there......

View Replies !
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?

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 !
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 !
Date Range :: Month, Year And Date In Separate Columns
I have a database where the date is stored in 3 different collums month, day, year. A am trying to retrieve data by a date range something like "1-1-2005" - "1-1-2007" or something but had quite some difficulty in doing it but I found a way and I am not sure that it is the best way but it appears to work well. Let me know what you think.

"SELECT * FROM database " +
"WHERE datey*365+DAYOFYEAR(CONCAT(datey, '-', datem, '-', dated)) " +
"BETWEEN " + StartDate + " AND " +
"EndDate + " " +
"ORDER BY datey, datem, dated;"

NOTE: StartDate and EndDate use the same formula of (year*365)+dayofyear

View Replies !
Add A Period 5 Places From The Right?
I'm trying to modify some latitude/longitude columns which have the values like:
3482787, -11782842

They're stored in text fields currently. I basically just need to put the decimal in the proper place, which should always be 5 places from the right, so i need to make the above value (and the other 6.3 million rows) look like this:
34.82787, -117.82842

I cant seem to find the function syntax to do this in MySQL, tho I'm sure it exists. I dont want to write a PHP script to do this because it seems like PHP chokes on me if I work on more than 500 thousand rows at a time.

View Replies !
Time Period Results
Can anyome tell me the php script to return data from a table which is less than 24 hours old. I have a timestamp on my table when data is added.

View Replies !
Grouping By A Date Period
Let's say I have a table with dates that range from January to May in each record.
Is it possible to group the records by a date range, for example:

I want to group the records by a date period of 1 month, starting at the 3rd day of each month. So what I'd want to see is, five records for each month (jan 3 to feb 3, feb 3 to march 3, march 3 to april 3, april 3 to may 3).At the moment I have the following:

select id, _date, sum(cost) from test
where
_date >= ' 2005-01-03' and
_date <= date_add('2005-01-03', interval 1 month)
group by extension
union
select extension, _date, sum(cost) from test
where
_date >= date_add(' 2005-01-03', interval 1 month) and
_date <= date_add('2005-01-03', interval 2 month)
group by extension

The trouble with this is that each month interval has its own select query and that the increase in the month is hard coded (interval 1 month for example). Is it possible to use SQL to inrement the month?

View Replies !
Selecting First Occurance In A Given Period Of Record
I have a table to log sessions and user (connect_id) id's, start time etc - see below

+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| connect_id | varchar(12) | | | | |
| session_id | varchar(32) | | | | |
| start_time | int(11) | | | 0 | |
| client_ip | varchar(16) | | | | |
+---------------+-------------+------+-----+---------+-------+

I need to create a report that will tell me, for instance, how many sessions were started today, that's easy I know but I also need another report that will tell me how many of those sessions were
first-time visitors.

View Replies !
Date Calculation For 24 Hour Period
I would like to automatically get the number of assignments received between a 24 hour period for the past 8 days. I am using

"where received >= date_add( now() , interval -1 day)" to get yesterdays assignments....

View Replies !
Dumping Data From A Certain Time Period
Every time I make changes to my MySQL database on my local PC, I have to dump the whole table on the server. This can get a bit annoying when the table contains thousands of records.Is there a way for MySQL to log all the updates you've made since a certain time and then use this file to dump it on the server?

View Replies !
Select And Displaying 90 Day Interval Over A Period
SELECT DATE_ADD('2008-09-07', INTERVAL 90 DAY)

What I'm basically after is to display a range of dates with a 90 day interval till a given date. As per the nultiple select statements below.

SELECT DATE_ADD('2008-09-07', INTERVAL 90 DAY)
SELECT DATE_ADD('2008-12-06', INTERVAL 90 DAY)
SELECT DATE_ADD('2009-03-06', INTERVAL 90 DAY)
SELECT DATE_ADD('2009-06-04', INTERVAL 90 DAY)
SELECT DATE_ADD('2009-09-02', INTERVAL 90 DAY)
SELECT DATE_ADD('2009-12-01', INTERVAL 90 DAY)
SELECT DATE_ADD('2009-12-01', INTERVAL 90 DAY)

View Replies !
Removing Data After A Certain Period Of Time
What I want to do is run a query that inserts data into my database, but removes itself on a set date. Is there any way to do this?

Basically, I have something like this:

INSERT INTO table (blah, blah2) VALUES (blah blah, 1)

I would like to do something like:

INSERT INTO table (blah, blah2) VALUES (blah blah, 1) {{{ INSERT CODE TO MAKE VALUES GO AWAY WHEN CURRENT TIME = SET TIME TO GO AWAY }}}

There is an alternative to this if I have to. This is all for a PHP script, and instead of having MySQL automatically remove the data, I could add a time to remove to the table, insert the value for it in the INSERT query, and run a query on the index page consisting of something like

<?php
$timeToRemove = SELECT_TIME_TO_REMOVE_FROM_DB;
if($currentTime => $timeToRemove)
{
REMOVE;
}
?>

so that every time someone hit the index page, it checks if it is time to remove the values from the DB and if it is, it does so. But of course, that adds an extra query/queries, and I'd like to avoid that.

Edit: It may be useful to note that this is for a message board system, and I am dealing with making usergroup changes temporary. So instead of removing the values, perhaps it would be more useful if I could simply have MySQL reverse itself after a certain time has passed.

But that seems unrealistic for some reason now that I think about it, so the alternative may be my best choice. Any suggestions from you all would be nice as well, if you've any ideas.

View Replies !
Selecting First Occurance In A Given Period Of Record (log Sessions And User)
I have a table to log sessions and user (connect_id) id's, start time etc - see below ...

View Replies !
Single Query For No Of Hits "Today", "This Month", "This Year"
Is it possible to construct a single query that fetches the no of pageviews "today", "this month", "this year" and "total since start"?

The table is very simple, one field for Date (YYYY-MM-DD) and one for the no of pageviews this day.

If not, would it be much slower/faster to divide the query into 4 different queries?

View Replies !
Generating DAILY Min&amp;Max Over A Period Of Time, Based On A "DateTime" Field
how to print the minimum and maximum of a specific field, between two datetimes (both having the time 02:00:00) - so I did this:

WHERE ((tblvalues.dtLPDateTime)>="2006-01-01 02:00:00" And (tblvalues.dtLPDateTime)<"2006-01-03 02:00:00"))

Now I want to print those min and max values but for each day in this cycle, i mean, for this example, there would be two records like:
Day Min Max
2006-01-01 02:00:00 -> 2006-01-02 02:00:00 | 40 | 59
2006-01-02 02:00:00 -> 2006-01-03 02:00:00 | 49 | 68
where at this point i`m getting min=40 and max=68

View Replies !
Room Reservation: See If A Time Period Is Open For A Particular Room...
this is stumping me...

i need to see if a time period is available for a something (in this case a room reservation).

it's not as simple as starttime < end and endtime > start...

for example a room is scheduled from 12:00 to 1:00pm and from 2:00 to 3:00pm.

how can you check if a user entered: from 1:00pm to 2:30pm?

i'm trying to UNION but that doesnt seem to work.

subselect?

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 !

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