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




Adding 1 Year To All Times


suppose that

dbX -> tableX

id columnX
1 1190815874
2 1192975748
3 1196695027
4 1196796789

how can i add 1 year all value where year is 2007 ?

my sql do not run

UPDATE `tablex` SET `columnx` = DATE_ADD(`columnx`, INTERVAL 1 YEAR)
WHERE DATE_FORMAT(FROM_UNIXTIME(`columnx`),'%X')) = 2007;




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Selecting A Date But Adding One Year To Result
I want to select some dates from the database but add one year to the result.

The tuple is called "TestDate" and i want to return it as DueDate in the results.

something like:

SELECT DATE_ADD('TestDate', INTERVAL 1 YEAR) AS 'Due_Date';

Get Year
i'm having problems getting the proper year.
my current date is :
november xx 2006, if i add 3 months from this date...
the outcome should be february xx 2007.

%Year%
What does %Year% represent in a query?Code:

SELECT * FROM `table` WHERE `field` NOT like '%Year%'

I checked google and the forum, but it seems to strip the %%.

Group By Year
I have a column in my table with this format. 2007-06-22 00:00:00. Is there any way for me create a mysql statement that will group the tables by year? I have a column with a number and I want to get a count of the number of positive numbers in this column and group them by year.

How To Get The Current Year
I'm a new bee to Mysql and i want to know how to get the Current year from the system date and then also know how to get the rows which are greater than the fetched year.

3 Top Buyers Per Year
I have a 2500 records in one table where i have registered the last 5 years sales. How can I
>>sum all the sales of a customer in a given year
>>get the top 3 buyers in a given year
>>for the whole period (5 years)
>>in only one sql stament, if possible.

Year Range
I am writing a document download system. In my database I have a From year, and a To year. These are the periods a particular document covers. For example, 2007-2008 or just 2007-2007.On my main page I want to list all documents that fall within the current year. So, I will need to list all documents that contain the year 2007 between the From and the To years....I hope this makes sense!I've tried doing:

"SELECT * FROM docs WHERE " & strcurrentyear & " YEAR(ffrom) BETWEEN YEAR(fto)"

Getting Dates From: Week, Year
Is it possible to retrieve the dates that belong to a certain week in a year?

If I query for Week 23 and Year 2006...I'd like to get this returned.

5-6-2006
6-6-2006
7-6-2006
8-6-2006
9-6-2006

Date Issue With The New Year.
SELECT *
FROM sermons
ORDER BY date DESC
And its spitting out the following code. the problem is that I want the new year then December of last year then November etc.

Here is what it spits out now

12-24-2006
12-10-2006
12-03-2006
11-26-2006
11-26-2006
11-22-2006
11-15-2006
11-12-2006
11-12-2006
11-08-2006
11-05-2006
11-05-2006
11-01-2006
10-29-2006
10-29-2006
10-25-2006
10-22-2006
10-22-2006
10-15-2006
10-15-2006
10-08-2006
10-08-2006
10-08-2006
10-07-2006
10-06-2006
10-05-2006
10-04-2006
10-03-2006
10-02-2006
10-01-2006
10-01-2006
01-07-2007
01-03-2007

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

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? .....

How To Represent A Calendar Year??
I am trying to represent a calendar year in a mySQL table. I need to represnt each month and all the days for each month in a certain year. Can anyone help me with this? I am basically making a small on-line booking application using php and mySQL.

Percentage Of 2 Year Data
I am having the toughest time trying to figure out how to get a percentage from my tables.

1. I Have 12 tables from 2005 named January2005, February2005 etc. up to December2005.
I also have 12 tables for 2006 name January2006 etc.

2.In these tables is a column named Result and the value is either Won or Lost.
I am counting how many times is says Won or Lost and getting a Total for each Month.
"Select Count(Result) From January2005 Where Result = 'Won';

3.I am getting a percentage for 2005 and 2006 just fine.
SELECT Round(((WonTotal)/Val((WonTotal)+(LoseTotal))*100))
FROM WinTotal, LoseTotal;

This is the problem: I need to take 2005 and 2006 and combine them to get a total percentage of Won.

Year Field Type
My question is, how do I prevent default data being entered into this field when I don't want to enter a year for the given row?

Appear 2 Times
i'm having this problem finding out the right sql query.
i have two tables A & B
the userid in table A appears as FK in table B
i need to list userid that appear 2 times or less in table B which has a where clause column3='Yes'

how do i go about it>?

Count Posts In A Year Per User
I need a query that will count posts in a year per user ...

Fiscal Year Totals - How To Calculate?
I am given the month number for the fiscal year. For exmaple, "4" indicates the fiscal year begins April 1 each year. April 2, 2005 would be Fiscal Year 2005. March 30, 2005 would be Fiscal Year 2004.

With the following table structure:
TABLE_A
id
date
amount

My current set up is like this, based on calendar year:

PHP

// get a list of years in the db
$years = $dbh->getCol("SELECT DISTINCT(YEAR(r.date))
FROM table_A r
ORDER BY YEAR(r.date) ASC");

foreach ($years as $s) {
    $yearSum = $db->getOne("SELECT SUM(r.amount)
    FROM table_A r
    WHERE YEAR(r.date) = '$s'");
    //echo something here
}

ISSUE1:
I need to calculate the total for each fiscal year. For example, April 1, 2004 - March 31, 2005. AND April 1, 2005 - March 31, 2006, and so on and so on for all years.

ISSUE2:
I need to calculate the total for each MONTH within each fiscal year. For example, during the fiscal year April 1, 2004 - March 31, 2005, what was January's total, Feb's total,... For each fiscal year.

Removing Year From CURDATE Or TO_DAYS
I'm trying to have a "today in history" page built with records pulled from a mysql table, and I just realized why it's not working... the year. I've read other threads here ("list birthdays in next 7 days", etc.) that point toward removing the year, but they also go by "DAYOFYEAR" in the cases I've found.

Here's the query I have now, which works if the years matchup:

SELECT DATE_FORMAT(`gamedate`, '%Y') as `gamedate`, location, opponent_id, oppname, result, score1, score2
FROM games, opponent
WHERE games.opponent_id = opponent.oppid AND TO_DAYS(CURDATE()) = TO_DAYS(`gamedate`)");
I've tried putting in a " - year " as I've noticed done on the other threads, but am getting nowhere.

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.


Sorting DATE Field By Year
I've have a field ('gamedate') in a table ('games') that is in DATE format, but what I can't figure out is how to use the year as part of a search form option. I'm hoping to get a drop down menu that is a list of years, that when selected will bring back just the records from that year, or in the future, use BETWEEN to find all records from a set group of dates.

Is there a step I'm missing to "extract" the "YYYY" part of the DATE field before using it? Or maybe there's a wildcard that needs to be stated to get "MM" and "DD" to equal "any"?

How To Pick Out The Year In A Stored Date
My dates are being stored in my database in this format:

2006-06-23 02:28:21

I am trying to run this simple query, but it's treating each row in the database as different dates because the time stamp is different for each one:

select date, count(*) as Searches from searches group by date order by sID desc;

How can I modify this query so that it just looks at the year in the date column and ignore the time?

Selecting Dates Ragardless Of Year
I have a table that holds dates in it for an availability calendar script.  At the moment I hold the season dates in a date field and colour code the calendar to show the rental season.  this is fine for the current year but if I want to display the next year (which has exactly the same rental seasons), I don't get anything coloured because the script is comparing the years along with the rest of teh date.

What I want to be able to do is for example if a rental period is from the 1st of July to the 31st of August to be able to pull out the dates from the database where just those months are included.  I store both a start date and an endate for each season in the same record.

I suppose what I am really after is a way to structure a select statement something like this.

select * from pricing where day and month of startdate <= day and month of currentdate and day and month of day and month of endate >= currentdate

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().

Select Year From Varchar Field
A cartographer customer of mine has populated a MySQL varchar field with information about the date in which his maps were created. He wants to pull out the date and sort records by it.

The rules he uses for approximating dates are as follows, where YYYY signifies the date he wants to sort by, zzzz represents garbage:

1) Explicit year:

YYYY

2) Year approximated:

{YYYY} zzzz

or (YYYY) zzzz

e.g. {1984} 1987 and he wants 1984

3). Circa:

ca. YYYY

---- Therefore what I would like to do, is pull out only the first four numbers, and use those numbers to sort on.

SELECT [grab the first four numbers only from column "Period"] AS year FROM maps ORDER BY year.

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').

MYSQL Fiscal Year Type
This is the SQL statment to generate by calender year type... which mean
from the january to December...

String sql = "SELECT TO_CHAR(REQUEST_DATE, 'MM') AS MONTH, SUM(REQUEST_TYPE)
AS HITS " +
"FROM REQUEST " +
"WHERE BRANCH=? AND CATEGORY=? " +
"AND TO_CHAR(REQUEST_DATE, 'YYYY')=? " +
"GROUP BY TO_CHAR(REQUEST_DATE, 'MM')";

I need the SQL statment to generate by fiscal year type...
Which is from the 1 April 06 to 31 March 07

just like when i choose 1st April 07, it will show me 1 April 07 to 31 March 08.

Leaving YEAR Fields Empty
I have a form which includes the option for users to enter a year into a YEAR defined field. The field is optional, so how do I ensure that if they leave it blank, it does insert the default 2000 value into the year field

Dates And Times
I have a field in a DB called "customerJobDate" which is configured to store full dates (ODBC dates) e.g. "2006-03-06 08:30:00". Now this does work i can update insert and delete the records perfectly, But if i query the DB asking for all dates that match 2006-03-06 regardless of the time (Date only) then the result returns 0 rows unless any of the dates in the column have 00:00:00 as the time.

This works: 2006-03-06 00:00:00
This does not work 2006-03-06 08:30:00

I hope someone can help me as I am finishing this app and this is the only thing holding me back.

One To Many Multiple Times
I have a 'links directory' database that currently contains 4 tables: category, subcategory, region and links. My links table contains company names and, among others, three fields catID, subcatID and regID. Each of these are related to primary keys in the other three tables, category (catID), subcategory (subcatID) and region (regID).

My issue is that the records in the links table can be in multiple regions, multiple subcategories and multiple categories, but the way I have it designed, each record in links can only be associated with a single catID, subcatID and regID.

Currently the only workaround I can think of it to have duplicate entries in the links table for a single company, but with every variation of catID, subcatID and regID. This will result in a very large table, but I cannot currently think of any better idea.

Upload Times
I need to upload 2 star catalogues to the mysql database. the first time i tried this i filled up the HD in 2 Days, my instructor mentioned that journalling was taking up most of the space and decided to remove-it.

now, with journalling turned off, i have started re-uploading the catalogues, but have noticed a significant decrease in "write" speed.

my question is, does journalling speed up writing data into mysql tables? i have roughly 180GB of data to upload, and it took me 4 days to upload 3GB's when last time it took me this time to upload 100GB.

Dates And Times.
You can't have two timestamp columns in a database both with the default now().
- why I would want to is not the issue.

You can't use the data and time functions, such as CURRDATE()/CURRTIME() provided by MySQL as defaults for date/time type columns.

Is there a way to use something like 'select currtime();' as the default for a column?

so my question is, how do I use ANYTHING other than one timestamp with the default value of now() for date/time defaults in MySQL.

About Dates And Times
I have form with drop down boxes, where folks enter dates and times, I have used implode and explode to format the dates, now I want to write those dates to mysql, I know mysql has its own date and time functions, is there a way to convert my php formatted dates and times into something that mysql will recognize and store as a time and date or does php have a function that will convert it and then allow it to be stored in date/time format in the database?

Number Of Times
I have a query that grabs 500 rows from 1 field within 1 table.

In this table. Each user will have 500 rows associated to them from within that table. So if there are 2 users then there will be 1000 rows. Each time 1 user executes the query, it grabs their 500 rows. If 2 users execute the query simultaneously, then this means that there are 1000 rows, all of which will be selected; 500 by one user and 500 by the other. If 3 users access the table simultaneously, then there are 1500 rows and so on. My question is how many users can execute this query simultaneously before we see performance loss?

Records Between Two Times
I have a table for a restaurant database with two fields open_time and close_time in TIME format. I want to be able to select all records that fall between open_time (when the restaurant opens) and close_time (when the restaurant closes).

I have this query:
Quote: Select hours_id from hours where curtime() between 'open_time' AND 'close_time';

It partially works, but its not working if the close_time is after midnight (i.e 1am = 01:00:00 in database). I can't figure out the issue with the difference between AM and PM.

Ordering Times
i have some vlaues in a database, they are 12 hour times, how would i go about sorting it so 12 comes before 1, as it is its going 1 2 3 4.... 12 etc etc, do i have to use a 24 hour time? then from there function it to show 12 hour when displayed

Comparing Times
I'm creating a voting system, and want to prevent people from cheating. Therefore I'm logging their IP, and the time they voted, and what I'm planning to do is have a script which will delete any records which have been in the database for say 24 hours.

To get the length of time I was gonne use:

HOUR(TIMEDIFF(NOW(),time))

Selecting Records Based On Month/year
I have a table of records with a date field in M/D/Y format. How do I select all the records for the month (and selected year)?

Measuring Query Times
I have read a few posts here and see that some people have questions regarding the length of time it can take to perfrom their queries.

I would be quite happy reaching that stage because at least I would know how long mine take. :|

How can the time delay be forced to output? Using MySQL 5.0.

Subtract Two Event Times
I am trying to formulate a complex query to get some good info straight from SQL, rather than post-processing in XL.

I have a table as follows:
EventID Integer (key)
ActionID Integer, 1 = event on, 2 = event off
dtStamp Date

I want to get the duration of each Event.

I.e. I need, for each Event:
dtStamp(actionID = 2) - dtStamp(actionID = 1)

I was going to try:

>create view EventOnTime as select EventID, dtStamp as EventOnDtStamp from EventLog where ActionID = 1;

>create view EventOffTime as select EventID, dtStamp as EventOffDtStamp from EventLog where ActionID = 2;

>select eventOnTime.EventID, eventOnTime.EventOnDtStamp - eventOffTime.EventOffDtStamp as EventDuration where eventOnTime.EventID = eventOffTime.EventID;

... but I can't create views with this version of SQL (server version: 4.0.20-standard-log)

Dump File Times Out?
I have a huge Access database (about 50,000) records. I use Access dumb to create a sql file which I can them go into phpmyadmin and import the records. Well, after a while the process times out. Is there a way I can import large amount of data into MYSQL without timing out?

Also the access database that I convert over gets updated every week. I don't know which records get updated or added. Also the app I am using only works with Access so I can not completely convert over. Is there a way I can update the MYSQL without having to import that huge file again. Maybe something that will not override the records that are same just change the modifed ones and add the new records.

Struggling With Dates And Times!
I'm using MySQL 3.23 - I know it's old but it comes as default on Linux distribs and I just want something consistent between home, my ISP and work.

I want to work out the time difference between two entries on my database (I'm using PostNuke and have two posts which are stored as integers, ie unix times). I can see that there is now a datediff() and timediff() function but they don't work hence why I mentioned the version I'm using.

Can anyone tell me how to get the difference between two dates - I am assuming I subtract one from the other but don't know how to convert the result into something useful (like days and hours etc) because I'm not sure what the unix time is made up of.

I guess an easier version of that lot is : is a unix time just a second count?

Disabling An Entry More Then 3 Times A Day.
Like if you enter 3 times a day the same text. It echo's something instead of writing in the database. Do i need to add a date on where the line was added to it?

Call To Database Times Out
using ZenCart 1.3.7, and when it calls to the database after clicking on "go to checkout" it hangs and then returns the following error message:

I get this message after clicking on "go to checkout"
2013 Lost connection to MySQL server during query in:

[select sum(tax_rate) as tax_rate from (tax_rates tr left join zones_to_geo_zones za on (tr.tax_zone_id = za.geo_zone_id) left join geo_zones tz on (tz.geo_zone_id = tr.tax_zone_id) ) where (za.zone_country_id is null or za.zone_country_id = 0 or za.zone_country_id = '223') and (za.zone_id is null or za.zone_id = 0 or za.zone_id = '12') and tr.tax_class_id = '1' group by tr.tax_priority]
2006 MySQL server has gone away in:

[select count(*) as total from sessions where sesskey = 'd60f1f220b761a5a176738c1a65de4b2']

Warning: Unknown(): A session is active. You cannot change the session module's ini settings at this time. in Unknown on line 0

I've checked with my host, and they are able to do a php call to the database just fine.

Slow Loading Times
It takes more than 30 seconds to load the phpmyadmin page. On a localhost server.
It says
Fatal error: Maximum execution time of 30 seconds exceeded in c:appservwwwphpmyadminlibrariesmysql_wrappers.lib.php on line 101

This sometimes also happens when loading my local website that uses MySQL.
I've tried reinstalling, but it doesnt help.

Export Records Times Out
I try to export all records from my db about once a week. I use phpmyadmin and select all tables structure and data and export as file. Well the problem now is it always times out when I do this. The db only contains about 18 tables and maybe 20,000 lines of data. The tables average about 12 fields each. So now I'm exporting a few tables at a time. Is there something I can do to change this?

Left Join 2 Times
SELECT f.id as id, f.forum_name as forum, f.forum_desc as description,
count(forum_id) as threads, u.name as mod
FROM forum_forum AS f
LEFT JOIN forum_posts AS p
ON f.id = p.forum_id
AND p.topic_id=0
LEFT JOIN forum_users AS u
ON f.forum_moderator = u.id
GROUP BY f.id

Output: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mod FROM forum_forum AS f LEFT JOIN forum_posts AS

Does this query contain any syntax errors? Can mysql perform left join 2 times?

Ordering Results By Number Of Times They Appear
I'm not really sure the best way to explain what I want to do, so I'm going to make a really simple example to illustrate what I mean.

Let's say I have a table with column "temperature". There are 5 entries that contain the word "hot", 3 entries that contain the word "medium", and 2 entries that contain the word "cold". However, these entries are not in any particular order.

Is there a "SELECT * FROM" statement which will return the results by order of popularity in the following manner?:

hot (5)
medium (3)
cold (2)

I have a script I'm working on and I'm trying to figure out the best way to do something like this.

Select Same Row Multiple Times Using Column
I've seen this asked before and although someone answered that it is possible, they did not post the solution, so if anyone can enlighten me that would be helpful.

Basiclly with table info


name | quantity
john | 3
anne | 1
will | 2
Return results

john
john
john
anne
will
will

Who Do I Write Select With Dates And Times
i have to cols, date and time. who can i do, SELECT between (date 1,time 1) to (date 2, time 2)?

for example i want to get the recordes between 2007-01-01 23:00:00 to 2007-01-03 03:00:00 ?


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