List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:January 6 2003 4:01am
Subject:Re: Update Year of Date Field using sql statement
View as plain text  
At 22:56 -0500 1/5/03, Bhavin Vyas wrote:
>I don't think there is a way to do that. Unless some one says there is(and
>tells us how to do it), I guess your only option is to write a script to do
>that.

Here's one way:

UPDATE table1
SET f1 = CONCAT('2002','-',MONTH(f1),'-',DAYOFMONTH(f1))
WHERE YEAR(f1) = 2003;

That is, synthesize the new date using the desire year, plus the
other parts of the existing date.

If you just want to subtract a year, do this:

UPDATE table1
SET f1 = DATE_SUB(f1,INTERVAL 1 YEAR)
WHERE YEAR(f1) = 2003;

>
>Regards,
>Bhavin.
>----- Original Message -----
>From: "Hakkan Lui" <hakkan@stripped>
>To: <mysql@stripped>
>Sent: Sunday, January 05, 2003 10:12 PM
>Subject: Update Year of Date Field using sql statement
>
>
>>  Dear all,
>>
>>  How can I change the year of the date field using sql statement?
>>
>>  It means something like:
>>  update table1 set year(f1) = '2002' where year(f1) = '2003';
>>
>>
>>  Thanks for anyone's help.
>>
>>
>>
>>  Regards,
>  > Hakkan Lui

Thread
Update Year of Date Field using sql statementHakkan Lui6 Jan
  • Re: Update Year of Date Field using sql statementBhavin Vyas6 Jan
    • Re: Update Year of Date Field using sql statementPaul DuBois6 Jan
      • Upgrading from MySQL 3.23.52 to 3.23.54Peter Teo6 Jan
        • RE: Upgrading from MySQL 3.23.52 to 3.23.54Anton Zavrin6 Jan
        • Re: Upgrading from MySQL 3.23.52 to 3.23.54Mark6 Jan
  • Re: Update Year of Date Field using sql statementDaniel Kasak6 Jan