How to get two date difference in Day/hour/min/secs pl

First of all,
Hello to All, i am new to Oracle DB, but i have little experience in Other Database such as Sybase, sql server etc
please kindly help me
in DoctorChart table i have DocName,Id#,Citcotype,Medtype,AdmitDate,DischargeDate(both admitdate & Discharge date is date formatted columns)
so how can i get the below differenceTime (which means Dischargedate-Admit Date in below format i.e, Day,Hours,Minutes,Seconds...)
DoctorName, ID #, Citco type, MEDtype, DifferenceTime
========= === ======= ======= ===========
Dr. KindaEmesko, 20045, Replace OutCard, ICH, 0 day 9 hours 11 minutes
Dr. KindaEmesko, 20098, Replace OutCard, ICH, 1 day 2 hours 34 minutes
Dr. KindaEmesko, 20678, Replace OutCard, ICH, 2 day 23 hours 52 minutes
Dr. KindaEmesko, 20212, Replace OutCard, ICH, 4 day 1 hours 00 minutes
Dr. KindaEmesko, 20345, Replace OutCard, BED, 3 days 14 hours 15 minutes
Dr. KindaEmesko, 20678, Replace OutCard, BED, 9 days 21 hours 52 minutes
Dr. KindaEmesko, 20015, Signature Overlay, Rest, 0 days 3 hours 29 minutes
Dr. KindaEmesko, 45678, Signature Overlay, Rest, 0 days 1 hours 29 minutes
Same way how can i get the Average Time for the above result (without ID columns)
DoctorName, Citco type, MEDtype, Avg DifferenceTime
========= === ======= ======= ===========
Dr. KindaEmesko, Replace OutCard, ICH, 2 day 1 hours 00 minutes
Dr. KindaEmesko, Replace OutCard, BED, 6 days 17 hours 15 minutes
Dr. KindaEmesko, Signature Overlay, Rest, 0 days 2 hours 29 minutes
Please just tell me how to get the two dates difference as day/hour/minute format
as well as how to get avg ( two dates difference as day/hour/minute format)
Please Help me
Thanks in advance

Well, instead of all these suggested manipulations you can simply use intervals. Oracle uses day as a unit in date arithmetic, so Dischargedate-Admit Date is number od days between two dates. Built-in function numtodsinterval can be used to convert it into interval. For example:
SQL> with t as (
  2             select trunc(sysdate) - 2 Admit_Date,
  3                    sysdate            Discharge_Date
  4               from dual
  5            )
  6  select  numtodsinterval(Discharge_Date - Admit_Date,'DAY') Hospital_Stay
  7    from  t
  8  /
HOSPITAL_STAY
+000000002 00:01:08.000000000
SQL>  SY.

Similar Messages

  • How to get the date of first day of a week for a given date

    Hi gurus
    can any one say me how to get the date of first day(date of Sunday) of a week for a given date in a BW transformations. For example for 02/23/2012 in source i need to get 02/19/2012(Sunday`s date) date in the result. I can get that start date of a week using  BWSO_DATE_GET_FIRST_WEEKDAY function module. But this function module retrieves me the  start date as weeks monday(02/20/2012) date. But i need sundays(02/19/2012) date as the start date. So it would be really great if anyone sends me the solution.
    Thanks
    Rav

    Hi,
    The simplest way would be to subtract 1 from the date date which you are already getting in transformation routine, but instead of doing that subtraction manually which might need bit of errort, you can simply use another FM to subtract 1 from given date.
    RP_CALC_DATE_IN_INTERVAL
    Regards,
    Durgesh.

  • Date difference in Days,hours minutes and seconds.

    Hi All,
    I have two date Suppose one is getdate() and other one is gatedate() +1 .I have to show the difference, currently I used a datediff in the stored proc which just shows the difference of the days :( but i need to show the difference in days:hours:minutes:seconds if possible.
    its a countdown with the current date. Like the two fields are sale_start_date and sale_end_date. Hope i am clear.
    Please let me know ASAP thanks in advance.Can anyone help me?all help is great help.
    Say the difference of
    12/6/2007 7:00:00 AM, 12/8/2007 8:00:00 AM  as 2 days 1:00:00)
    Thanks
    N

    One of the problems of using DATEDIFF when dealing with either seconds or milliseconds is that this function will result in execution errors if the start and end dates span then entire domain of possible dates.  Below is an alternative that seems to work over the entire date domain.  A couple of things to note:
    1. This select converts the days and seconds of each date into BIGINT datatypes to avoid the overflow error
    2. This select uses a CROSS APPLY operator; in this case I chose CROSS APPLY to suggest the possibility of converting this select into an inline table function.
    I suspect that if you dig around this forum and the net that you will find a better routine, but here is yet another alternative:
    declare @test table
    ( startDate datetime, endDate datetime)
    insert into @test values
    ('6/1/9', getdate()),
    ('6/9/9 15:15', '6/10/9 19:25:27.122'),
    ('6/9/9 15:15', '6/10/9 13:25:27.122'),
    ('6/9/9', '6/10/9 00:00:01'),
    ('1/1/1760', '12/31/2999')
    select
      startDate,
      endDate,
      [Days],
      [Hours],
      [Minutes],
      [Seconds]
    from @test
    cross apply
    ( select
        cast((endSecond - startSecond) / 86400 as integer) as [Days],
        cast(((endSecond - startSecond) % 86400) / 3600 as tinyint) as [Hours],
        cast(((endSecond - startSecond) % 3600) / 60 as tinyint) as [Minutes],
        cast((endSecond - startSecond) % 60 as tinyint) as [Seconds]
      from
      ( select
          86400 * cast(convert(integer, convert(binary(4),
                        left(convert(binary(8), startDate),4))) as bigint)
            + cast(convert(integer, convert(binary(4),
                right(convert(binary(8), startDate),4)))/300 as bigint)
          as startSecond,
          86400 * cast(convert(integer, convert(binary(4),
                        left(convert(binary(8), endDate),4))) as bigint)
            + cast(convert(integer, convert(binary(4),
                right(convert(binary(8), endDate),4)))/300 as bigint)
          as endSecond
      ) q
    ) p
    /* -------- Sample Output: --------
    startDate               endDate                 Days        Hours Minutes Seconds
    2009-06-01 00:00:00.000 2009-06-22 08:28:36.670 21          8     28      36
    2009-06-09 15:15:00.000 2009-06-10 19:25:27.123 1           4     10      27
    2009-06-09 15:15:00.000 2009-06-10 13:25:27.123 0           22    10      27
    2009-06-09 00:00:00.000 2009-06-10 00:00:01.000 1           0     0       1
    1760-01-01 00:00:00.000 2999-12-31 00:00:00.000 452900      0     0       0
    (5 row(s) affected)
     EDIT:
    I based the routine more-or-less on Thilla's reply.
    Kent Waldrop

  • How to get the date of 60 days before 1999/03/01?

    Hi, I have a question about Date and GregorianCalendar here. I have a string "1999/03/01" and I would like to know the date that 60 days before 1999/03/01. What should I do it?
    I only went this far:
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
    String date = "1999/03/01";
    Date day = dateFormat.parse(date);
    GregorianCalendar calendar = new GregorianCalendar();
    : <--- ??
    So, can anyone please tell me what should I do next??
    -jxchou

    Put this in the search box for this forum at the right: add days +date
    The first 2 hits are about your question.
    The Forum search is your friend...

  • How to get  the date of the day or eeven the hour

    hi!
    i am interested in a function or a class that allows me to get the day date and that allows me too tp specify its format like :
    mmddyyyy or ddmmmmyy and so on ....
    can you please help me !
    thanks

    yes thanks for the help ! but could you please convey
    me which java function allow me to get the actual day
    date? i mean like"Now" one of visual basic !! sothat i
    can pass it to the formet() function!
    Try these links:
    http://www.javaworld.com/javaworld/javaqa/2001-10/01-qa-1005-dateformat.html
    http://www.javaworld.com/javaworld/jw-03-2001/jw-0330-time.html
    http://www.javaworld.com/jw-12-2000/jw-1229-dates.html

  • How to get the date of first day of the week

    hi ,
    how can i get the first day of the current week ?
    i have tried the following
    note : my sysdate is 3rd april 2007
    select trunc(sysdate , 'ww') from dual -- 4/2/2007
    select trunc(sysdate , 'w') from dual -- 4/1/2007
    select trunc(sysdate - 4 , 'ww') from dual -- 3/26/2007 -- shld return 25th mar 2007
    select trunc(sysdate - 4 , 'w') from dual -- 3/29/2007 -- shld return 25th mar 2007pls advise
    tks & rgds

    Hi!
    I'm considering MONDAY as the first working day of the current week. And, the code is accordingly --
    SQL> select to_char(sysdate - to_number(decode(to_char(sysdate,'DY'),'TUE','1',
      2                               'WED','2',
      3                               'THU','3',
      4                               'FRI','4')),'dd-mon-yyyy') res
      5  from dual;
    RES
    02-apr-2007Regards.
    Satyaki De.

  • How to get two vga monitors on a mac mini 2012

    Hi Guys,
    please forgive any ignorance that follows. I am a new convert from a PC and have bought a Mac Mini 2012. I want to be able to use a monitor that I can see my music programme but run a second monitor that will allow me to display visuals from a VJ programme. Here is my journey.
    I bought the mac mini and the thunderbolt to vga adapter. Generic VGA monitor - worked a treat. I then wanted to run a second generic vga monitor form the hdmi port. After a lot research I chose an adapter for £15 that one of the reviews said worked perfectly for a mac mini and VGA. Bought it form Amazon. Didn't work - no signal etc - refund. Then I thought I would buy a monitor / DVD with a HDMI cable and do hdmi to hdmi and use that as the music monitor and use the thunderbolt port for the projector and VJ programme. Bought one from Asda. Plugged in great picture etc worked a treat but got a ground hum from new HDMI monitor. More research and realised that ground hum was a nightmare. HDMI monitor back and refund.
    It is doing my head in.
    I will be a happier man if someone could say that they have a mac mini 2012 and they bought this HDMI VGA converter and use a generic vga monitor and it works a treat. There is only so much stuff I can return before my lick runs out.
    I don't think I'm asking for much.
    Any help would be gratefully received.
    Cheers Pete

    Sorry, but I can not safely suggest a digital HDMI to analog VGA converter or if any would even work with the Mac Mini because I do not have and have not personally tested any.
    I can only suggest that instead of dropping more money into adapters or an HDMI to VGA converter, that perhaps' you should consider replacing one if not both with a more modern digital monitor that support either HDMI and/or DVI.

  • How to get exact date and time difference?

    Hi,
    When i am using the below sql statement:
    SELECT (TO_DATE('7/27/2006 05:00:15 PM','MM/DD/YYYY HH:MI:SS PM') - to_Date('7/27/2006 8:30:13 AM','MM/DD/YYYY HH:MI:SS AM')) * 24 hours FROM DUAL;
    the output is:
    Hours
    8.50055555555556
    But Actually it is 8.30
    So how can i get exact days and time difference between two dates in Oracle?
    Thanks....
    Regards,
    Suman Sakinala
    Edited by: SSN on Sep 19, 2008 1:27 AM

    Or more clearly (this time I have my date_from and date_to the right way around hehe!)
    SQL> ed
    Wrote file afiedt.buf
      1  WITH t as (select TO_DATE('7/27/2006 05:00:15 PM','MM/DD/YYYY HH:MI:SS PM') as dt_to,
      2                    TO_DATE('7/27/2006 08:30:13 AM','MM/DD/YYYY HH:MI:SS AM') as dt_from FROM DUAL)
      3      ,d as (select (dt_to-dt_from)*24 as diff_hrs from t)
      4  -- end of dates
      5  SELECT TRUNC(diff_hrs) as hours
      6        ,TRUNC(((diff_hrs) - TRUNC(diff_hrs))*60) as mins
      7        ,TRUNC(((((diff_hrs) - TRUNC(diff_hrs))*60) - TRUNC(((diff_hrs) - TRUNC(diff_hrs))*60))*60) as secs
      8* FROM d
    SQL> /
         HOURS       MINS       SECS
             8         30          2
    SQL>

  • How to get changed data in ALV in Web Dynpro for ABAP

    METHOD on_data_check .
    DATA:
        node_spfli                          TYPE REF TO if_wd_context_node,
        node_sflight                        TYPE REF TO if_wd_context_node,
        itab_sflight2                        TYPE if_display_view=>elements_sflight.
      node_spfli = wd_context->get_child_node( name = if_display_view=>wdctx_spfli ).
      node_sflight = node_spfli->get_child_node( name = if_display_view=>wdctx_sflight ).
      CALL METHOD node_sflight->get_static_attributes_table
        IMPORTING
          table = itab_sflight2.
    this code is ..get all data(changed and not changed)
    but i want get changed data only, not all data.
    how to get changed data?
    Edited by: Ki-Joon Seo on Dec 27, 2007 6:04 AM

    Hi,
    To get only the changed data in the ALV grid of a WD, you need to capture the "ON_DATA_CHECK" of the ALV grid.
    To this please do the following in the ALV initialization of the ALV table settings :
        lr_table_settings->set_data_check(
                IF_SALV_WD_C_TABLE_SETTINGS=>DATA_CHECK_ON_CELL_EVENT ).
    You may also do this:
        lr_table_settings->set_data_check(            IF_SALV_WD_C_TABLE_SETTINGS=>DATA_CHECK_ON_CHECK_EVENT)
    The above two ways would depend on when do you need to check for the changed data. If you want to check the data as soon as it is entered, then use the first method. Else, use the second method.
    You need to register an EVENT HANDLER for this event.(You may do this in your VIEW or Component Controller).
    In this Event handler, you would find an importing parameter R_PARAM which is a ref type of      IF_SALV_WD_TABLE_DATA_CHECK.
    The attribute T_MODIFIED_CELLS of this interface IF_SALV_WD_TABLE_DATA_CHECK will contain the modified cells of the ALV with the old & new values.

  • How to get the date for the first monday of each month

    Dear Members,
    How to get the date for the first monday of each month.
    I have written the following code
    SELECT decode (to_char(trunc(sysdate+30 ,'MM'),'DAY'),'MONDAY ',trunc(sysdate+30 ,'MM'),NEXT_DAY(trunc(sysdate+30 ,'MM'), 'MON')) FROM DUAL
    But it look bith complex.
    Abhishek
    Edited by: 9999999 on Mar 8, 2013 4:30 AM

    Use IW format - it will make solution NLS independent. And all you need is truncate 7<sup>th</sup> day of each month using IW:
    select  sysdate current_date,
            trunc(trunc(sysdate,'mm') + 6,'iw') first_monday_the_month
      from  dual
    CURRENT_D FIRST_MON
    08-MAR-13 04-MAR-13
    SQL> Below is list of first monday of the month for this year:
    with t as(
              select  add_months(date '2013-1-1',level-1) dt
                from  dual
                connect by level <= 12
    select  dt first_of_the_month,
            trunc(dt + 6,'iw') first_monday_the_month
      from  t
    FIRST_OF_ FIRST_MON
    01-JAN-13 07-JAN-13
    01-FEB-13 04-FEB-13
    01-MAR-13 04-MAR-13
    01-APR-13 01-APR-13
    01-MAY-13 06-MAY-13
    01-JUN-13 03-JUN-13
    01-JUL-13 01-JUL-13
    01-AUG-13 05-AUG-13
    01-SEP-13 02-SEP-13
    01-OCT-13 07-OCT-13
    01-NOV-13 04-NOV-13
    FIRST_OF_ FIRST_MON
    01-DEC-13 02-DEC-13
    12 rows selected.
    SQL> SY.

  • How to get the Date in a particular format?

    Hi,
    How to get the Date in the below format? I will be passing the year in my method..
    2/10/2003 9:46:52 PM
    D/M/YYYY H:M:S A
    public Date getDate (String year) {
    Here i want to get the Date in this format
    2/10/<Passed Year> 9:46:52 PM
    Thanks

    This is my code
    public static Date getCalendar(Calendar calendar,int getYear) {
    String      formatted_date="";
         int year = getYear;
         int month = calendar.get(Calendar.MONTH+1);
         int day = calendar.get(Calendar.DATE);
         int hour = calendar.get(Calendar.HOUR);
         int min = calendar.get(Calendar.MINUTE);
         int sec = calendar.get(Calendar.SECOND);
         int am_pm =calendar.get(Calendar.AM_PM);
         formatted_date = month+"/"+day+"/"+year+" "+hour+":"+min+":"+sec+" PM";
         System.out.println("formatted_date is "+formatted_date);     
         o/p : formatted_date is 1/4/2006 1:44:21 PM
         SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    //     DateFormat dateFormat =DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
         Date passdate = new Date();
         try {
              passdate = dateFormat.parse(formatted_date);
         } catch (ParseException e) {
              System.out.println("Invalid Date Parser Exception "+e.getLocalizedMessage()+"DateFormat is "+dateFormat);
              System.out.println("The Date inside the function is "+passdate+"and the year passed is "+year);
    o/p : The Date inside the function is Sat Apr 01 00:00:00 IST 2006and the year passed is 2006
         return passdate;
    Expected O/P is 3/1/2006 1:44:12 PM
         }

  • I lost my Iphone and I stored my photos on icloud, how to get those data back? My PC also not working.

    I lost my Iphone and I stored my photos on icloud, how to get those data back? My PC also not working.

    Welcome to the Apple Community Rahul.
    Photos in photo stream...
    You can log into your iCloud account on another computer or device and enable photo stream to see your photos. You should do this as soon as possible because photo stream in the cloud only keeps photos for 30 days and each day you delay, you will lose another days photos.
    Photos in the camera roll...
    If you kept a back up of your device you can use it to restore to a replacement device, this will restore all of the photos in your camera roll and isn't time limited.

  • How to Compare two Dates in java

    How to Compare two Date Field after getting the values from jTextField1.getText() and jTextField2.getText().

    Date d1=DateFormat.getDateInstance().parse(yourstring1);
    same for d2
    d1.compareTo(d2);
    could be that i misrememberd the exact naems of some functions or mixed up something in the equence of d1=

  • [ASK] How to get system date and substring / concate in data manager dynami

    Hello guys.
    I want to run package DM with the input have default value.
    The selection is look like this :
    Dimension : CATEGORY
    Source : PLAN_2011
    Destination : FORECAST_2011
    Dimension : TIME
    Source : 2011.JAN,2011.FEB,2011.MAR,2011.APR,2011.MAY,2011.JUN,2011.JUL,2011.AUG,2011.SEP,2011.OCT,2011.NOV,2011.DEC
    Destination : <same>
    How to get system date year and do the substring / concate ?
    So dimension category source will be PLAN_<YYYY>, destination = FORECAST_<YYYY>
    Dimension source = <YYYY>.JAN,<YYYY>.FEB,<YYYY>.MAR,<YYYY>.APR,<YYYY>.MAY,<YYYY>.JUN,<YYYY>.JUL,<YYYY>.AUG,<YYYY>.SEP,<YYYY>.OCT,<YYYY>.NOV,<YYYY>.DEC
    Depend on year system date.
    Thank you.

    Stuart,How are you storing OnSaleDate. If you are using OnSaleDate as an attribute dimension then you can write a Custom Defined Function to either:1- query your system for the current date and return the number of seconds that have elapsed since 1/1/1970. This is by definition the begining of the Epoch and how Essbase treats Attribute Dimensions of the Date type.public static long getDateInSeconds() {           Calendar cal = Calendar.getInstance();           return cal.getTime().getTime()/1000;}2- Write a Custom Defined Function that will accept the OnSaleDate and return the number of days sincepublic static double daysSince(double myDate) {     return (getDateInSeconds()-myDate )/86400;}

  • How to get last date of the week

    hi,
    how to get last date of the week like FM WEEK_GET_FIRST_DAY gives the date of the first day of the week i need the date of the last day of the week..
    thnx

    data : p_week type KWEEK,
    p_Date type SYDATUM.
    p_week = <incoming value in week of year>
    CALL FUNCTION 'WEEK_GET_FIRST_DAY'
    EXPORTING
    week = p_week
    IMPORTING
    DATE = p_date
    EXCEPTIONS
    WEEK_INVALID = 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.
    To get the last day of the week.
    p_date = p_date + 6.
    You can find the available fm in the system from se37 transaction code.

Maybe you are looking for

  • WRT160N S-l-o-w with Win 7 Device?

    Recently added a new Laptop running Windows 7. Experiencing very slow "download" speeds (~600kbps). Upload seems good at 3.2 Mbps. Set up and initial connectivity went fine, all settings and conditions on the new wireless endpoint look ok too. Using

  • Validation code for a credit application form

    Can some one tell me how to validate a form? Here is the codes that i have in entered - when the form appears the validation statement shows up on the form. <script language="javascript"> function validate(){      if (document.LeftField.name.firstnam

  • Date function in DI

    Hi all I need to get only date part of the a global value which is of DateTime type. I checked the DI functions, but couldn't find what I was looking for there. Date_part function returns part of the date value in int format, but I need it as a DateT

  • Mexico Digital Invoice printout

    Hi Experts, I am working on Mexico localisation.We have requirement for Digital invoice printing and also XML file generation.I know SAP has given a functionality for XML file generation and it can be done but for Digital invoice prinout there is no

  • How to summarize age ranges i.e 0-5, 6-10........?

    Post Author: SunilKanta CA Forum: General Hi, I am new to crystal reports, i am designing a report i.e cross tab report as shown below, AGE TABLE 0-5 6-10 11-15 16-20 21-25 26-28 CLASS A Count                  7                15 CLASS B Count