-1

I have an food catering application that should calculate if the order time have passed 15 minutes. I have an idea in mind where I should calculate the time difference between the current time and the order time, but I am not sure how to do it. Does anyone have a simple solution to solve this?

Dmitriy
  • 5,525
  • 12
  • 25
  • 38
M. IG
  • 31
  • 5

1 Answers1

0

Subtracting two date values in Oracle results in number of DAYS. Therefore, you'd have to do some math in order to get hours (or minutes). Here's an example:

SQL> col diff_days format 90D00000
SQL> col diff_hours format 90D00000
SQL> col diff_minutes format 90D00000
SQL>
SQL> with test as (select to_date('29.12.2017 16:05', 'dd.mm.yyyy hh24:mi') d_order,
  2                       to_date('29.12.2017 16:39', 'dd.mm.yyyy hh24:mi') d_now
  3                from dual)
  4  select
  5     d_now - d_order              diff_days,
  6    (d_now - d_order) * 24        diff_hours,
  7    (d_now - d_Order) * (24 * 60) diff_minutes
  8  from test;

DIFF_DAYS DIFF_HOURS DIFF_MINUTES
--------- ---------- ------------
  0,02361    0,56667     34,00000

SQL>

You'd do similarly: D_NOW would be SYSDATE, while D_ORDER would be a value stored in a(n ORDERS) table.

Littlefoot
  • 131,892
  • 15
  • 35
  • 57