Hakkan Lui wrote:

>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';
>  
>
If you have a field for _just_ the year, you can use the above statement.
If you have the year embedded in a date field which has other data (eg
days and months) then you'll have to use the substring function (or you
could get fancy with some of mysql's date functions, but I wouldn't in
this case).

MySQL stores dates in the format yyyy-mm-dd, so you just have to do
something like:

update table1 set year(f1) = concat('2003' , '-',
substring(year(f1),6,5)) where substring(year(f1),1,4)='2002';

Or something. I haven't checked the above, so beware...
Read up on concat.

Also I would reconsider using those brackets in the year field:
year(f1). I don't know whether brackets in a field name are supported,
but brackets usually indicate a function.

-- 
Daniel Kasak
IT Developer
* NUS Consulting Group*
Level 18, 168 Walker Street
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: [EMAIL PROTECTED]
website: www.nusconsulting.com


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to