Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query question

Status
Not open for further replies.

buzzt

Programmer
Oct 17, 2002
171
CA
I am trying to extract all the dates from a date column in my MySQL database with the year 2003 to update them to 2004 using PHP. Here's what I tried - unsuccessfully - (to extract - haven't gotten to the update part yet):

select * from TABLE where (select extract(year from DATE COLUMN)=2003)

The SELECT EXTRACT(YEAR FROM) is from the MySQL website, but doesn't seem to work this way.

Any ideas?
 
select * from table where year(datefield)=2003

 
and
update tablename
set datefield=adddate(datefield,INTERVAL 1 year)
where year(datefield)=2003

should perhaps do the trick for the update
 
Thanks!

Any idea about the second query (the update)? I've been playing with this but nothing yet.

update TABLE set year(DATE COLUMN)=year(curdate()) where year(DATE COLUMN)='2003';
 
The only problem with doing it that way (which will probably work) is that if there are any years prior, they will not get updated the the current year (2004).

Ultimately, I would like to update all years to the current year without specifying the current year each time if possible, which is why I thought of curdate().
 
I think we posted at the same time ;)
 
I still can't get it to set all years to current year. Is it going to be year(curdate()). That does not seem to work.
 
update TABLE set DATE COLUMN = adddate(DATE COLUMN , interval (year(curdate()) - year(DATE COLUMN)) Year )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top