So i need to update some dates on an Oracle Database, the field is a datetime, but i only want the date updated and leave the time as it is... There query goes like this:
update table
SET field = to_date('07312010','MMDDYY');
But it's overriding the hours, minutes and seconds from the field, i want to update the date but i want the hour to be left the same, any thoughts?
Try this: update table_name set date_field = to_date('2009/05/11','yyyy/mm/dd') ; Hope this helps.
Finally, you can change the default DATE format of Oracle from "DD-MON-YY" to something you like by issuing the following command in sqlplus: alter session set NLS_DATE_FORMAT='<my_format>'; The change is only valid for the current sqlplus session.
To display the date column, simply use TO_CHAR along with proper FORMAT MODEL. UPDATE Regarding dynamic SQL. 'UPDATE XX_TABLE last_update_date = ''' || SYSDATE || ''', WHERE 1=1';
You could use:
UPDATE TABLE
SET field = TO_DATE('07312010' || ' ' || TO_CHAR(field, 'HH24:MI:SS'),
'MMDDYY HH24:MI:SS');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With