DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: Date and time calculation?

  1. #1
    Join Date
    Dec 2002
    Posts
    1

    Question Date and time calculation?

    I have a table with 4 fields.

    Field 1: as_date datatype: date
    Field 2: as_time datatype: number precision:4 scale:2

    Field 3: dc_date datatype: date
    Field 4: dc_time datatype: number precision:4 scale:2

    I need to subtract the comnined value of field 3/4 from the combined value of 1/2 in order to find out how many days and hours have elapsed.

    I am not sure how to do merge the fields and perform a calculation with the datatypes being different.

    PHP Code:
    Possible
    My thanks in advance.

    Adrian

  2. #2
    Join Date
    Feb 2001
    Posts
    180
    Maybe this example will help:
    set serveroutput on
    clear
    declare
    ld_date1 date := to_date('20021204','yyyymmdd');
    ld_date2 date := to_date('20021207','yyyymmdd');
    ln_time1 number(4,2) := 14.24; -- Hours assumed
    ln_time2 number(4,2) := 12.30; -- Hours assumed

    ln_diff number (10,2);
    begin
    ln_diff := ld_date2 - ld_date1; -- Difference in days
    dbms_output.put_line('Diff days : '||ln_diff);
    ln_diff := ln_diff * 24 ; -- Difference in hours
    dbms_output.put_line('Diff hours : '||ln_diff);
    ln_diff := ln_diff + (ln_time2 - ln_time1);
    dbms_output.put_line('Diff total : '||ln_diff);
    end;
    /
    Regards
    Ben de Boer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width