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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to update DATE data. 4

Status
Not open for further replies.

fiat2

Programmer
Nov 26, 2002
104
US
Using Oracle 9.
I've got some data in a DATE field and right now it looks something like this:
10/18/0008

I would like to update all the records to take the records current Month, Day and update the year to 2008.
As it is, all the data that I need to update is from 2008, if that helps.

thanks.
 
Hi,
Try something like:
Code:
Update table_name set 
Date_field = 
to_date(to_text(Date-Field,'MM')||'/'||to_text(Date-Field),'DD')||'/'||'2008','MM/DD/YYYY');

[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 

-- or --
Code:
Update table_name 
   set Date_field = TRUNC(SYSDATE);
[3eyes]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 

Oooooh, now I understand, you want to KEEP the column's day/month and just change the year, right?

OK, do tuckbear's code using the TO_CHAR() function:
Code:
Update Table_Name
   Set Date_Field = To_Date(To_Char(Date_Field,'MM')||To_Char(Date_Field),'DD')||'2008','MMDDYYYY');
[noevil]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Or perhaps a little simpler:
Code:
Update Table_Name
   Set Date_Field = To_Date(To_Char(Date_Field,'MMDD')||'2008','MMDDYYYY');

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
“Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty.”
 
Hi,
As usual Santa, short and sweet.....Here's a star.

( Working with different systems makes remembering syntax difficult..hence, my to_text instead of to_char goof [blush])

[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Wow! great little thread here.

Thanks to all for your valuable input!!!
 
One more soluion:

Update Table_Name
Set Date_Field = trunc(sysdate,'Y')+ (Date_Field-trunc(Date_Field,'Y'));

Contrary to other solutions it preserves time part of the field. I also suppose that it may be faster but just a little bit.

Regards, Dima
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top