Skip to content
Advertisement

why subtracting two time doesn’t work properly in oracle

I want to calculate system time till that day 17:00 in minutes in plsql, and I write the below query but it doesn’t work :

select to_date ((trunc(sysdate)||' 17:00' , 'DD-MM-YYYY hh24:mi')-to_date(sysdate, 'DD-MM-YYYY hh24:mi'))*60 from dual 

can someone help me?

Advertisement

Answer

My guess is that you want

select (trunc(sysdate) + interval '17' hour - sysdate) * 24 * 60 minutes_to_1700
  from dual

If that isn’t what you want, it is helpful to provide some details and a test case to show exactly what you want to happen rather than just saying that something “doesn’t work”. My guess is that you’re getting an error because your second to_date is doing an implicit date to string conversion using your session’s nls_date_format which probably doesn’t match the explicit date format you specified. But that’s just a guess.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement