Date substraction

how to get correct result for the time subtraction of minutes
for the following query
select (to_date('14-06-2012 11:10:00','dd-mm-yyyy hh24:mi:ss') - to_date('14-06-2012 11:00:00','dd-mm-yyyy hh24:mi:ss'))*60*60 as
result from dual
RESULT
25
i want the output as 10 minutes.
could you help me.
I am using oracle 10g version.

ʃʃp wrote:
/* Formatted on 2012/06/14 17:54 (Formatter Plus v4.8.8) */
SELECT EXTRACT (MINUTE FROM (  TO_DATE ('14-06-2012 11:10:00', 'dd-mm-yyyy hh24:mi:ss')
- TO_DATE ('14-06-2012 11:00:00', 'dd-mm-yyyy hh24:mi:ss')
) DAY TO SECOND) AS RESULT
FROM DUAL;
Erm... that only works if the minutes are in the same hour, otherwise it's not giving the difference in minutes for the time part of the date...
SQL> ed
Wrote file afiedt.buf
  1  SELECT EXTRACT (MINUTE FROM (  TO_DATE ('14-06-2012 13:10:00', 'dd-mm-yyyy hh24:mi:ss')
  2                               - TO_DATE ('14-06-2012 11:00:00', 'dd-mm-yyyy hh24:mi:ss')
  3                              ) DAY TO SECOND) AS RESULT
  4* FROM DUAL
SQL> /
    RESULT
        10I would have thought the correct answer already given would have pointed that out.

Similar Messages

  • Oracle Date Substraction

    Hi all,
    I have a question regarding Date substraction. I've read somewhere that the standard unit of Date Substraction of Oracle is days. However my requirements is to have result format in hours. Example:
    Date1: 1/21/2010 08:00:00 AM
    Date2: 1/22/2010 10:00:00 AM
    Date2 - Date1 = 1 (day). If I need to convert to hours, I can achieve by multiply it by 24. But in fact the result for this should be 26 hours.
    1 more example for this:
    Date1: 1/21/2010 08:00:00 AM
    Date2: 1/21/2010 10:00:00 AM
    Date2 - Date1 - 0 (day). While in fact it should be 2 hours.
    In short, I want Date substraction to give me result in hours rather than days. Is there anyway to achieve this objective using pure SQL in Oracle? or do I have to manipulate using some kind of programming language?
    I've received a reply from the other thread saying that I could get the number of hours by mulitply the number of days by 24. This is true only if Oracle stores data in format like: 1.2 days after substraction. Is this the case with Oracle?
    Thank you very much.
    Thanh.

    babaravi wrote:
    use extract function. you can achieve it.
    1  SELECT EXTRACT(HOUR FROM
    2  (SYSTIMESTAMP - TO_TIMESTAMP('30.07.2009 10:00:00', 'DD.MM.YYYY HH24:MI:SS'))) AS hour
    3* FROM   dual
    SQL> /
    HOUR
    23
    SQL>
    ?:|
    The OP asked for Date substraction, not timestamps. Also, your solution doesn't give the total number of hours between the date/times...
    SQL> ed
    Wrote file afiedt.buf
      1  SELECT EXTRACT(HOUR FROM
      2  (SYSTIMESTAMP - TO_TIMESTAMP('30.07.2009 10:00:00', 'DD.MM.YYYY HH24:MI:SS'))) AS hour
      3* FROM   dual
    SQL> /
          HOUR
            22
    SQL> ed
    Wrote file afiedt.buf
      1  SELECT (SYSDATE - TO_DATE('30.07.2009 10:00:00', 'DD.MM.YYYY HH24:MI:SS'))*24 AS hour
      2* FROM   dual
    SQL> /
          HOUR
    6982.25944
    SQL>Just a slight difference. ;)

  • Date Substract Format

    I'm trying to format following query.
    SELECT TO_CHAR(START_DATE, 'HH:MM:SS'), TO_CHAR(END_DATE, 'HH:MM:SS'),
    TO_CHAR(END_DATE - START_DATE, 'HH:MM:SS')
    FROM TIMES
    Oracle returns following message:
    ORA-01481: invalid number format model
    Somebody knows how to convert from number to date values?
    I appreciate some help
    Best regards

    The problem is that when you subtract two dates, Oracle returns a number -- which is the 'portion of the day' -- you can take the result and multiply it by 86400 to get the number of seconds in a day and then convert that back to a date... Once this is converted back to a date - you can then convert it to a character - with your date format... Sounds kind of sloppy - and it is, but it works..
    here's the example i used (which is REALLY SLOPPY)
    SELECT TO_CHAR(TO_DATE(((SYSDATE - TO_DATE('28-JUN-2002 08:00','DD-MON-YY HH24:MI')) * 86400), 'SSSSS'), 'HH:MI:SS') FROM DUAL
    Now, I'll attempt yours without testing..
    SELECT TO_CHAR(START_DATE, 'HH:MM:SS'), TO_CHAR(END_DATE, 'HH:MM:SS'),
    TO_CHAR(TO_DATE(((END_DATE - START_DATE, 'HH:MM:SS') * 86400), 'SSSSS'), 'HH:MI:SS')
    FROM TIMES
    Hope this helps!
    Michelle
    I'm trying to format following query.
    SELECT TO_CHAR(START_DATE, 'HH:MM:SS'), TO_CHAR(END_DATE, 'HH:MM:SS'),
    TO_CHAR(END_DATE - START_DATE, 'HH:MM:SS')
    FROM TIMES
    Oracle returns following message:
    ORA-01481: invalid number format model
    Somebody knows how to convert from number to date values?
    I appreciate some help
    Best regards

  • How to add minutes to date in java

    I have date in string variable, i have to add/subtract minutes from it, please adivce , how i could do in java 1.5
    sample data
    String olddate = "12/16/2010 4:58:29 PM"
    String minutes1 = "300"
    i would like to get value as below for above data
    String newdate ="12/16/2010 9:58:29 PM"

    Use SimpleDateFormat to convert the date object to string. Once the string object converted to date object use the getTime() method to get the date in milliseconds.
    Now you can easily adds/substract the date object.
    Remember, the resulting long value from getTime() method is in milliseconds, to get the value in minutes you need to multiply it by 1000 and by seconds in a minutes, that is 60.
    When your subtraction/adds done convert it back to date object.
    This is the codes:
    import java.text.SimpleDateFormat;
    import java.text.ParseException;
    import java.util.Date;
    public class DateCalculator {
         public static void main(String[] args) throws ParseException {
              String olddate = "12/16/2010 4:58:29 PM";
              System.out.println("old Date: "+olddate);
              SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy h:mm:ss a");
              long oldDateInMillis = formatter.parse(olddate).getTime();
              String minutes1 = "300";
              String newDateAdds = formatter.format(new Date(oldDateInMillis + Long.valueOf(minutes1)*1000*60 ));
              String newDateSubstract = formatter.format(new Date(oldDateInMillis - Long.valueOf(minutes1)*1000*60 ));
              System.out.println("new Date [Additions] : "+newDateAdds);
              System.out.println("new Date [Substraction] : "+newDateSubstract);
    }

  • Fields For Good Reciept and Issed !

    Hi all,
    I want the fields for the goods reciept and good issued for getting the stock for a particular material as on to date (which is my selection screen) ...
    I have selected the sales data from the VBRK and VBRP tables which is for sales information and now i need to find out the Stock information. My Requirement is to maintain sales stock and to show the Turn Over Ratio ???
    Can you tell me the tables and the fields where i will get them ...
    I m calculating my Stock as:
    Stock (as on date) = Substracted Value (Reciepts - issues ) - current stock.

    In MSEG there is field for Sales order number as well as item number from that you can get the Goods issues quantity,similarly in MSEG you also have purchase order number and purchase order item numner from which you can get the goods purchased quantity by passing it to VBAP and EKPO respectively.
    Regards
    Mohamed Mansoor
    Message was edited by:
            Mohamed Mansoor Kasim

  • Substract one day to a date in a XSLT mapping

    Hi,
    I need to map a ENDDA field to a new field but subtracting a day, and reformatting the date, e.g
    from:
    <ENDDA>20090213</ENDDA>
    I need:
    <ENDDA>12.02.2009</ENDDA>
    For reformatting, sub string and concat with . is working, but how can I substract a day, including the handling where the date is the first day of the month?
    thx for your inputs

    I think this will help you.
    Create one UDF and insert 2 parameters.
    First parameter as your date
    second is number of hours 24:00:00
    Code:
       //write your code here
    SimpleDateFormat sd = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
    SimpleDateFormat sdTarget = new SimpleDateFormat("MM/dd/yyyy");
    try {
    Date currentDate = sd.parse(a);
    Date compareDate = sd.parse(a.substring(0,10) + " " + b);
    if (currentDate.after(compareDate)  )
        Calendar c = Calendar.getInstance();
    c.setTime(sdTarget.parse(a));
    c.add(Calendar.DATE,1);
    a = sdTarget.format(c.getTime());     
    else
    //a = "before"
    a =  a.substring(0,10) ;
    catch(Exception e)
    return a;
    This might need little modification as your need.
    After that use Date Transformation function which will convert date in your required format.
    Thanks,
    Hetal
    Edited by: hetal shah on Feb 17, 2009 9:43 PM

  • Substract days to a date

    Does somebody know a method to substract to a given date (in String format dd/mm/yyyy) a given number of days??
    public String restarDias(String fecha, int dias) throws Exception {
    DateFormat df = DateFormat.getDateInstance();
    Date fechaD = df.parse(fecha);
    return dateResult;
    }.. thanks!

    Hi,
    you can do this easily when you define a Calendar and then apply the method:
    //somewhere in code
    //Calendar Cal = Calendar.getInstance();
    Cal.add(Calendar.DATE,3); //to add 3 days
    Cal.add(Calendar.DATE,-1);//to substract one day
    greetings,
    alina3

  • How to substract two date&time values

    Well,i just need to substract last visited date&time value from systemdate. The last visited date&time(from the filed named SONBULUNMAZAMANI, ) is selected from table (IHALE_KATILIMCILAR ) in the format DD-MM-RRRR HH24:MI and systemdate is in the same format. And i need to get value in minutes. Then i need to check if the value is greater then 20 minutes, finally i will update database and set IHALE_KATILIMCILAR.AKTIF=0. Here is the code i used;
    DECLARE
    MinDiff number;
    DateTime1 ihale_katilimcilar.sonbulunmazamani%TYPE;
    BEGIN
    select t.sonbulunmazamani into DateTime1 from ihale_katilimcilar t where t.ihlkodu=141 and t.ihlaltktgkodu=132 and t.id_iliski=193;
    MinDiff := ABS( TO_DATE( TO_CHAR(SYSDATE, 'DD-MM-RRRR') || TO_CHAR(SYSDATE , 'HH24:MI'), 'DD-MM-RRRR HH24:MI' ) - TO_DATE( TO_CHAR(DateTime1, 'DD-MM-RRRR') || TO_CHAR(DateTime1, 'HH24:MI'), 'DD-MM-RRRR HH24:MI' ) );
    DBMS_OUTPUT.PUT_LINE('Difference is ' || MinDiff);
    END;
    However the result i get is always pointed values such as ,1895833333333333333333333333333333333333. How can i handle this?
    And here is the scripts of table:
    create table IHALE_KATILIMCILAR
    KULADI VARCHAR2(20),
    SONUC NUMBER(1),
    AKTIF NUMBER(1) default 1,
    SRKTKODU VARCHAR2(10) not null,
    SONBULUNMAZAMANI DATE default sysdate,
    SIRA NUMBER(1) default 0,
    MESAJ VARCHAR2(200),
    ID NUMBER(6) not null,
    IHLKODU NUMBER not null,
    IHLALTKTGKODU VARCHAR2(10) not null,
    ID_ILISKI NUMBER,
    IHLSIRA NUMBER(1) default 0,
    CEVAP VARCHAR2(200)
    insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
    IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
    values ('asd', null, 1, '4444', to_date('19-02-2008 10:29:44', 'dd-mm-yyyy hh24:mi:ss'), 0, 'süre talep 2', 76, 145,
    '135', 345, 0, 'al sna süre 77');
    insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
    IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
    values ('asd', null, 1, '4444', to_date('20-02-2008 14:49:52', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 77, 145, '135',
    345, 0, null);
    insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
    IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
    values ('asd', null, 1, '4444', to_date('19-02-2008 10:29:44', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 78, 145, '135',
    345, 0, null);
    insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
    IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
    values ('asd', null, 1, '4444', to_date('19-02-2008 10:29:44', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 79, 145, '135',
    345, 0, null);
    insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
    IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
    values ('KEMMM', null, 0, '42', to_date('17-03-2008 09:29:20', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 63, 141, '134',
    191, 0, null);
    insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
    IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
    values ('MLK', null, 1, '46', to_date('07-03-2008 09:52:20', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 64, 141, '134', 192,
    0, null);
    insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
    IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
    values ('KEM.ESM', null, 1, '44', to_date('06-03-2008 13:28:50', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 61, 145, '135',
    189, 0, null);
    insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
    IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
    values ('KE.ES', null, 1, '45', to_date('07-03-2008 11:16:41', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 69, 141, '133',
    197, 0, null);
    insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
    IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
    values ('KEMMM', null, 0, '42', to_date('17-03-2008 09:29:20', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 65, 141, '132',
    193, 1, null);
    insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
    IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
    values ('KE.ES', null, 1, '45', to_date('07-03-2008 11:16:41', 'dd-mm-yyyy hh24:mi:ss'), 2, null, 66, 141, '132',
    194, 1, null);
    insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
    IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
    values ('MLK', null, 1, '46', to_date('07-03-2008 09:52:20', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 67, 141, '132', 195,
    1, null);
    insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
    IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
    values ('KEMMM', null, 0, '42', to_date('17-03-2008 09:29:20', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 68, 141, '133',
    196, 0, null);
    insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
    IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
    values ('KEM.ESM', null, 1, '44', to_date('12-03-2008 15:00:58', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 70, 142, '252',
    198, 1, null);
    insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
    IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
    values ('KE.ES', null, 1, '45', to_date('10-03-2008 10:08:17', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 71, 142, '252',
    199, 1, null);
    insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
    IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
    values ('KEM.ESM', null, 1, '44', to_date('10-03-2008 10:08:56', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 72, 143, '253',
    200, 1, null);
    insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
    IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
    values ('MLK', null, 1, '46', to_date('12-02-2008 13:34:40', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 73, 143, '253', 201,
    1, null);
    insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
    IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
    values ('KE.ES', null, 1, '45', to_date('06-03-2008 14:09:40', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 60, 145, '136',
    188, 1, null);
    insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
    IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
    values ('KEM.ESM', null, 1, '44', to_date('06-03-2008 13:28:50', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 74, 145, '136',
    202, 1, null);
    insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
    IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
    values ('KE.ES', null, 1, '45', to_date('06-03-2008 14:09:40', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 75, 145, '135',
    203, 0, null);
    Thanks...

    What version of SQLServer do you have? Datediff is not an Oracle built-in function.
    OP:
    THe difference between two dates in Oracle is in days. The decimal portion refers to partial days, so you need to convert that to the required precision. Also, both sysdate and your column are date type, and contain a time portion, so you do not need all the to_date/to_char stuff. Something like:
    SQL> SELECT end_dt, start_dt, (end_dt - start_dt) * 24*60 diff
      2  FROM (SELECT sysdate end_dt, TRUNC(sysdate) start_dt
      3        FROM dual);
    END_DT             START_DT                 DIFF
    17-mar-08 10:39:39 17-mar-08 00:00:00     639.65John

  • Function to get the date after substraction

    Hi Gurus,
    I understand that the function "RE_ADD_MONTH_TO_DATE" is used for calculate the date after added certain month(s).
    But, how do I do it in the other way. What I mean here is I want to substract the date.
    For example my current date is 09.05.2008, substract 3 years is 09.05.2005.
    All ideas and suggestion are greatly appreciated.
    Thanks.

    Hi ,
    u can use the same function module RE_ADD_MONTH_TO_DATE with passing months in negetive number like,
    month = -36.
    in the function module.
    regards,
    kk.

  • Regarding substracting dates

    Can we Substract 2 dates in the format 'WW-YYYY'
    to get number of weeks??

    Well your criteria aren't dates, they are just strings, so you need to extract the relevant parts and put those into the SQL... e.g.
    SQL> ed
    Wrote file afiedt.buf
      1  WITH mydates as (select '51-2008' as end_date, '24-2008' as start_date from dual)
      2  -- END OF TEST DATA
      3  select ((to_date('01-01-'||substr(end_date,4),'DD-MM-YYYY')+(to_number(substr(end_date,1,2))*7))
      4        - (to_date('01-01-'||substr(start_date,4),'DD-MM-YYYY')+(to_number(substr(start_date,1,2))*7))
      5         ) / 7 as weeks
      6* from mydates
    SQL> /
         WEEKS
            27
    SQL>

  • Regarding substract 2 dates and display o/p in days

    hi all
    in my program i hv to substract to diffrent dates field and display result in days.
    i.e suppose i hv to substract 10/6/2008-1/06/2008
    display should be 9 days

    Hi,
    CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
        EXPORTING
          date1                         = date1
          date2                         = date2     OUTPUT_FORMAT                 = '02'
       IMPORTING
        YEARS                         =
        MONTHS                        =
         DAYS                          = v_days
       EXCEPTIONS
         INVALID_DATES_SPECIFIED       = 1
         OTHERS                        = 2
      IF sy-subrc <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    In v_date you get the number of days between the two dates.
    Reward points if useful.
    Thanks & regards
    Deepika

  • Substract date from date?

    hello,
    i try to substract a date from sysdate and format it like 'HH24:MI:SS'.
    SELECT ID
    , to_char (DLC,'DD.MM.YY HH24:MI:SS') as DateLastChange
    , to_char (sysdate,'DD.MM.YY HH24:MI:SS') as ToDay
    , to_char ((to_date(SYSDATE,'DD.MM.YY HH24:MI:SS') - to_date (DLC ,'DD.MM.YY HH24:MI:SS'))) as Time
    FROM TEST_TABLE
    result:
    ID | DateLastChange | ToDay |Time
    1045 | 14.02.03 17:24:04 | 27.02.03 12:29:30 | 10
    but only full day's are displayd.... i need day's and minutes
    thank's for help

    Hi Rainer,
    if you are using Oracle9i, you can use Day to Second Interval.
    SELECT sysdate, hiredate ,NUMTODSINTERVAL( TO_CHAR( sysdate - hiredate ), 'day' ) from emp;
    It gives you even the fractional millisecond difference upto a precision of 9.
    SQL> insert into emp(empno,hiredate) values( 100, sysdate-1);
    SQL> select NUMTODSINTERVAL(to_char(sysdate-hiredate),'day') from emp where empno=100;
    NUMTODSINTERVAL(TO_CHAR(SYSDATE-HIREDATE),'DAY')
    +000000001 00:03:13.000000000
    Regards
    Elango.

  • SUBSTRACTING 2 DATES TO GET THE DIFFERENCE IN MINUTES

    Hi
    I want to substract 2 dates and to get the difference in minutes. Can you help me with that ?
    Thanks

    select (sysdate - (sysdate - 10)) * 24 * 60 from dual
    where
    sysdate - date1
    (sysdate -10) - date2
    24 - number of hours per day
    60 - number of minutes per hour
    Is this what you need?

  • Date operations in java: how to substract two dates

    dear all
    I want to substract two date and return the number of days between them
    and I want to make a method that return the number of monthes between two dates
    please help

    Kayaman wrote:
    Check out the Calendar class.Hello Kayaman,
    From a quick glance at its API, I haven't found it obvious that Calendar could fulfill such need under 10-lines algorithms. As per Joda-time's proponents, it's one of those computation that are unintuitively hard or convoluted using the stock JDK date&time classes.
    If you're comfortable with Calendar, maybe you'd find it interesting to voice your opinion in this other topic: {thread:id=1982257}. Thanks in advance.
    Hello OP,
    apologies for plugging that discussion in your topic. But I do think it's closely related.
    I noticed you marked both replies as helpful. I'd like to know your feedback on those replies: have you tried both approaches, and succeed with one, or both? Have you met difficulties with either?
    Thanks, and good luck anyway.
    J.

  • Substract 3 monts to a date in oracle bi publisher 11g

    Hey forum
    I need to create a sql query data set that groups my info by fiscal year.
    what I'm having on my data set sql query editor right now is something like
    select YEAR ("Credit Memo"."Cm Fecha Creacion") as yearGroup
    from .................
    and I'm using this field for my grouping.
    the problem is that my fiscal years go from apr to apr.
    so i would need something like select YEAR ("Credit Memo"."Cm Fecha Creacion" - 3 monts) as yearGroup
    this will pull those rows from jan,feb and march to the last year. for example YEAR(02/02/2011 - 3 monts) = 2010
    I've tried things like YEAR ("Credit Memo"."Cm Fecha Creacion" - "Credit Memo"."Cm Fecha Creacion") but it happens
    that i cannot subtract from a date on the sql publisher editor.
    I've spent several hours browsing and googling without any sucess :(
    I can't even find a list of date functions (like the "YEAR" function i'm using) for publisher sql editor. This would help a lot because maybe I can figure out some sort of alternative solution.
    Any help will be SUPER welcomed
    Thanks!

    Thanks so much for your help!
    I've used add_months against oracle databases without any problem
    Sadly this publisher sql editor is not taking the same functions as a regular sql + command line :(
    Do you have any other idea?
    Thanks!

Maybe you are looking for