简体   繁体   中英

Oracle - Update date field

I have a field called schedule_finish that I want to update, but when I do, the date on front end is showing a day behind the date in the database. ie. When I update the date to 30-AUG-19 , it's showing August 29th on the front end. I can fix this problem by adding a second to the date I want to update the field to, but I'm not sure how to do it in this case.

Here's my SQL:

update inv_investments
set schedule_finish = TRUNC('30-AUG-19') + 1/(24*60*60)
where id=5064001;

But this gives me the error:

ORA-00932: inconsistent datatypes: expected DATE got NUMBER

But, for example, if I do this, it works:

update inv_investments
set schedule_finish = TRUNC(updated_date) + 1/(24*60*60)
where id=5064001;

/* where updated_date field is '30-AUG-19' */
/* shows same date on both back and front end as desired */

Is there a way to store the date I want to update the field to in a variable then reference the variable in the update statement, and/or is there a better way to accomplish this?

Thanks in advance

You are adding to a string. The string has to be converted to a date

update inv_investments
  set schedule_finish = TO_DATE('30-AUG-19','dd-MON-yy') + 1/(24*60*60)
  where id=5064001;

You should be able to do this:

set schedule_finish = DATE '2019-08-30'

You should be getting August 30th. If you are not, something highly suspicious is happening. One possibility is a timezone issue. However, adding one second would not fix that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM