Diff between two date

i hv two date type data along with time lets say
p1 '21-jan-2001 12:43:05'
p2 '22-jan-2001 13:33:10'
i want diff between two dates p1-p2 will give only the number of days in between but i want even the time also
for ex in the above ex the diff etween two days is 1 day 1hr bla bla.......

Check that link... it will offer you a few alternatives:
http://www.orafaq.com/faq/how_does_one_get_the_time_difference_between_two_date_columns
HTH,
Thierry
with dates as (
select to_date('22-jan-2001 13:33:10', 'DD-MON-YYYY HH24:MI:SS') as date1,
to_date('21-jan-2001 12:43:05', 'DD-MON-YYYY HH24:MI:SS') as date2 from dual)
SELECT floor(((date1-date2)*24*60*60)/3600)
            || ' HOURS ' ||
            floor((((date1-date2)*24*60*60) -
            floor(((date1-date2)*24*60*60)/3600)*3600)/60)
            || ' MINUTES ' ||
            round((((date1-date2)*24*60*60) -
            floor(((date1-date2)*24*60*60)/3600)*3600 -
            (floor((((date1-date2)*24*60*60) -
            floor(((date1-date2)*24*60*60)/3600)*3600)/60)*60) ))
            || ' SECS ' time_difference
FROM dates;
24 HOURS 50 MINUTES 5 SECS Edited by: Thierry H. on Mar 3, 2011 5:51 PM

Similar Messages

  • Date/hour diff between two date/timestamps - however dataype in DB is curr varchar

    Hi All
    Could someone please help me?
    I would like the T-SQL statement for hours passed between two date/timestamps within a table
    e.g
    Login_Time
     22/02/2014 11:03:12.925297 AM    (Data type in DB is varchar(50))
    Logout_Time
    22/02/2014 11:19:01.701073 AM      (Data type in DB is varchar(50))
    Thank you Kindly

    DECLARE @dt AS VARCHAR(50)='22/02/2014 11:03:12.925297 AM'
    DECLARE @dt1 AS VARCHAR(50)='22/02/2014 11:19:01.701073 AM' 
    SELECT DATEDIFF(hour,dt_from,dt_to) FROM
    SELECT CAST(SUBSTRING(@dt,7,4)+ SUBSTRING(@dt,4,2)+SUBSTRING(@dt,1,2)+
    SUBSTRING (@dt,11,17)  AS DATETIME2) dt_from,
    CAST(SUBSTRING(@dt1,7,4)+ SUBSTRING(@dt1,4,2)+SUBSTRING(@dt1,1,2)+
    SUBSTRING (@dt1,11,17)  AS DATETIME2) dt_to
    ) AS Der
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to get the diff between two dates  -  # of days

    Hi Experts,
    I have requirement to know the difference between dates. In my presentation layer two columns as created date and updated date. I want to know the difference in # of days in the presentation services.
    Please provide some pointers.
    Thanks in adv
    svr

    Hi,
    In the presentation layer you can create a column with a custom formula of this:
    TIMESTAMPDIFF(SQL_TSI_DAY, datecolumn1,datecolumn2)
    The result shown in the column will be the difference in days between the two dates.
    Regards,
    Matt

  • Diff between Two dates

    I am Unable to find the Diffrence betweeen two dates. can you please help how i find the difference between tow dates.
    Thanks,

    Hi,
    As Bhushan showed, the result of subtracting one DATE from another is the number of days between them.
    If
    d1 is 06:00:00 on April 19, 2010, and
    d2 is 12:00:00 on April 20, 2010, then
    d2 - d1is 1.25, because d2 is 1 day plus 6 hours (6/24 = .25) days after d1.
    If you want the difference in months or years, use the MONTHS_BETWEEN function:
    MONTHS_BETWEEN (d2, d1)is the number of months that d2 is after d1, and
    MONTHS_BETWEEN (d2, d1) / 12is the number of years.

  • Need help with finding diff between two dates

    Hi,
    could someone please point me in the right direction.
    I want to substract two dates to get the age of a person. One of the date is sysdate and the other is date of birth. Assuming we remove the time part of the date.
    Best Regards,

    Hi,
    select
    timestamp, sysdate,
    decode(sign(sysdate-timestamp - 1/24), -1,
    round(24*60*(sysdate-timestamp)) || ' minutes old ',
    decode(sign(sysdate-timestamp - 1), -1,
    round(24*(sysdate-timestamp)) || ' hours old ',
    decode(sign(sysdate-timestamp - 14), -1,
    trunc(sysdate-timestamp) || ' days old ',
    decode(sign(sysdate-timestamp - 60), -1,
    trunc((sysdate-timestamp)/7) || ' weeks old ',
    decode(sign(sysdate-timestamp - 365), -1,
    round(months_between(sysdate,timestamp)) || ' months old ',
    round(months_between(sysdate,timestamp)/12,1) || ' years old '
    ))))) age
    from t;
    Regards

  • How to get time diff between to date

    Hi all,
    How can I get the time diff. between two date in a single query
    as in the example below-
    select
    to_char(sysdate,'dd-mm-yyyy hh:mi:ss') d1,
    to_char(sysdate-45,'dd-mm-yyyy hh:mi:ss') d2,
    months_between(sysdate,(sysdate-45)) mon_diff
    /* how can I get the time diff in terms of hour ,min, seconds*/
    from dual

    314214, The difference between any two Oracle dates is measured in Days and fractions thereof.
    A day = 24 hrs, = 1440 minutes, = 86400 seconds
    Use the mod function on the difference
    HTH -- Mark D Powell --

  • I wanted to know how do you calculate the number of days between two dates

    i wanted to know how do you calculate the number of days between two dates in java ? i get both the dates from the database. i guess there are many issues like leap year and Febuary having diff no of months ..etc.

    thanks..
    I solve my problem as
    public class MyExample {
        public static void main(String a[]) {
            String stdate = "2009-03-01";
            java.sql.Date currentDate = new java.sql.Date(System.currentTimeMillis());
            java.sql.Date preDate = java.sql.Date.valueOf(stdate);
            System.out.println(currentDate);
            System.out.println(preDate);
    //        int dateCom = preDate.compareTo(currentDate);
    //        System.out.println(dateCom);
            long diff = currentDate.getTime() - preDate.getTime();
            int days = (int) Math.floor(diff / (24 * 60 * 60 * 1000));
             System.out.println(days);
    }

  • How to retrieve day between two dates?

    Hi all,
    Hope doing well,
    sir i am retrieving day between two dates in sql server like this.
    select datediff(day,'2012-10-03 00:00:00.000','2012-10-05 00:00:00.000')
    and getting result that is: 2
    but how this type of query i'll use in oracle?
    thanks,

    Just do minus
    diff := date_variable2-date_variable1;The difference sill be in days.
    If you want just the differences in days (Neglecting time part)
    diff := trunc(date2)-trunc(date1);

  • How to caluclate tat between two dates of one timestamp field

    Hi,
    could some one help how to caluclate days between two dates of single timestamp filed and with this
    query
    Select * from m_activity_transaction where actn_opp_id in (
    Select actn_opp_id from m_activity_transaction where ACTN_ACTV_ID = 218
    Group by actn_opp_id
    having count(*) > 1 ) and ACTN_ACTV_ID = 218
    order by actn_performed_on
    iam getting output is
    ACTN_ID ACTN_OPP_ID ACTN_PERFORMED_ON
    319415 95831 27-JAN-12 11.06.20.000000 AM
    315249 95831 08-FEB-12 05.32.54.000000 PM
    301927 103509 20-DEC-11 04.01.43.000000 PM
    301458 103509 19-DEC-11 04.51.03.000000 PM
    294841 115840 10-JAN-12 03.20.12.000000 PM
    312062 115840 11-JAN-12 05.17.06.000000 PM
    and i nedd to caluclate no.of days between two dates like 27-JAN-12 11.06.20.000000 AM and 08-FEB-12 05.32.54.000000 PM where actn_id is unique AND ACTN_OPP_ID IS NOT UNIQUE.
    Thanks in Advance,
    vvr.

    This way?
    with data as
    select 315249 a, 95831 b, to_timestamp('27-JAN-12 11.06.20.000000 AM', 'DD-MON-RR HH.MI.SS.FF6 AM') dt from dual union all
    select 319415, 95831, to_timestamp('08-FEB-12 05.32.54.000000 PM', 'DD-MON-RR HH.MI.SS.FF6 AM') from dual union all
    select 301927, 103509 , to_timestamp('20-DEC-11 04.51.03.000000 PM', 'DD-MON-RR HH.MI.SS.FF6 AM') from dual union all
    select 301458 , 103509 , to_timestamp('19-DEC-11 04.01.43.000000 PM', 'DD-MON-RR HH.MI.SS.FF6 AM') from dual union all
    select 363810 , 144656 , to_timestamp('27-JUN-12 12.43.28.000000 PM', 'DD-MON-RR HH.MI.SS.FF6 AM') from dual union all
    select 363500 , 144656 , to_timestamp('26-JUN-12 11.41.50.000000 AM', 'DD-MON-RR HH.MI.SS.FF6 AM') from dual union all
    select 363354 , 144656 , to_timestamp('25-JUN-12 12.41.13.000000 PM', 'DD-MON-RR HH.MI.SS.FF6 AM') from dual
    select a, b, diff
      from (
            select a, b, extract( day from (dt - lag(dt) over (partition by b order by dt, a)) ) diff
              from data
           ) tab
    where tab.diff is not null;
    A                      B                      DIFF                  
    319415                 95831                  12                    
    301927                 103509                 1                     
    363500                 144656                 0                     
    363810                 144656                 1

  • Count between two dates.

    dear friends
    i want fetch count between two dates.
    my query is like below.
    SELECT (to_date('19-mar-2012','dd-mm-yyyy')-to_date('01-apr-2012','dd-mm-yyyy')) FROM dual
    its given out like -13 but i want in positive mod like 13 only not '-' Sign.

    just use abs() function to your query to get the positive value
    SELECT abs(to_date('19-mar-2012','dd-mm-yyyy')-to_date('01-apr-2012','dd-mm-yyyy')) diff FROM dual

  • How to calculate the hour difference between two dates?

    hi all,
    how to calculate the hour difference between two dates?
    eg i trying this...
    ((TO_DATE(TO_CHAR(GRNi.reference_date_4,'hh24:mi'),'hh24:mi') -
    TO_DATE(TO_CHAR(NVL(GRNi.reference_date_3,SYSDATE),'hh24:mi'),'hh24:mi'))*24)*60 Act_Hr
    Reg.
    AAK

    Hi
    To break the diff between 2 dates into days, hours, minutes, sec -- you can use the following:
    select to_char( created, 'dd-mon-yyyy hh24:mi:ss' ),
    trunc( sysdate-created ) "Dy",
    trunc( mod( (sysdate-created)*24, 24 ) ) "Hr",
    trunc( mod( (sysdate-created)*24*60, 60 ) ) "Mi",
    trunc( mod( (sysdate-created)*24*60*60, 60 ) ) "Sec",
    to_char( sysdate, 'dd-mon-yyyy hh24:mi:ss' ),
    sysdate-created "Tdy",
    (sysdate-created)*24 "Thr",
    (sysdate-created)*24*60 "Tmi",
    (sysdate-created)*24*60*60 "Tsec"
    from all_users
    where rownum < 50
    HTH
    RangaReddy

  • Calculate difference between two dates/times

    Hi all,
    Is there any function module to calculate difference between two dates/times which are in TIMESTAMPL format.
    I need to know how many millisconde(second,minutes, hours... )there is between these two times.
    Please, It is urgent
    Thank you all.
    Karim

    hi,
    try the following function
    CALL FUNCTION 'CCU_TIMESTAMP_DIFFERENCE'        
          EXPORTING                                  
               timestamp1 = timestamp1               
               timestamp2 = timestamp2               
          IMPORTING                                  
               difference = diff                     
          EXCEPTIONS                                 
               OTHERS     = 1. 
    the above function gives the difference in seconds...
    try the following  code to set the resolution to milliseconds..
    SET RUN TIME CLOCK RESOLUTION LOW
    check the thread for details:
    SET RUN TIME CLOCK RESOLUTION?
    all the best!!!
    Regards,
    Aparna

  • Calculate the difference between two dates times in infopath form 2013

    Hi,
    I have an infopath 2013 form that contains three fields:
    2 date time and the 3rd contains the difference between the two in hours
    how I can make the difference between the two so that the display will be like this:
    Date Time1           08/21/2014           22:00 
    Date Time2           08/22/2014           1:00
    Diff Field                                             3:00

    Hi,
    Please refer to the following article which matches your requirement exactly.
    Calculate the difference between two date picker controls in InfoPath using rules and formulas - no code!
    Please mark it answered, if your problem resolved.

  • Calculate the difference between two dates

    I would like to calculate the difference between two dates in PL/SQL and return the result as a number of days expressed as an integer value.

    Denes,
    A fair point, I should really have posted this on the SQL forum (I'm new to the forum as well as PL/SQL) but thanks for responding anyway. It does raise a question as to how to implement this in ApEx though.
    I have created the function and am calling it as shown below from the source window of a form. The source type is 'PL/SQL expression or function' and the expression in the source window of the form is:
    calc_date_difference (:p26_c_payment, :p26_c_rec)
    The two parameters being passed are of type date but I'm not sure how to handle the ruturned number and populate the form in ApEx with this value.
    Is it possible to do it this way or am I taking completely the wrong approach?
    Regards
    Sandy
    This is not ApEx related but SQL related:
    CREATE OR REPLACE FUNCTION calc_date_difference (
    p_date_1   VARCHAR2,
    p_date_2   VARCHAR2
    RETURN NUMBER
    v_difference   NUMBER;
    v_sql_err      VARCHAR2 (4000);
    BEGIN
    v_difference := TRUNC (TO_DATE (p_date_1)) - TRUNC
    (TO_DATE (p_date_2));
    RETURN v_difference;
    CEPTION
    WHEN OTHERS
    THEN
    v_sql_err := SQLERRM || CHR (10) || CHR (10) ||
    SQLCODE;
    ND calc_date_difference;and
    SQL> SELECT calc_date_difference ('23.01.2007',
    '20.01.2007') diff
    2    FROM DUAL;
    DIFF
    3
    Denes Kubicek                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Working days between two date fields and Changing Factory Calendar

    Hi,
    I have to calculate working days between two date fields excluding the weekends and public holidays for Switzerland.
    I have written the routine using factory calender and its working fine except for two problems now:
    1. If any one of the date field is empty then teh rsult should be zero.
    2. And the below code is working from 1996 but my cleints wants it to work for years before 1996 as well.
    I also tried to change the Start date in SCAL for factory calendar but it says enter values between 1995 to 2020.
    I am new to ABAP. Please help me how i can achieve these for below code.
    DATA: IT_HOLIDAYS type TABLE OF ISCAL_DAY,
          IS_HOLIDAYS TYPE ISCAL_DAY.
    DATA: T_DATE TYPE SY-DATUM,
          P_DATE TYPE SY-DATUM.
    DATA : X_DATE(4) TYPE C.
    DATA: CNT TYPE I.
    REFRESH : IT_HOLIDAYS.
    CLEAR : IT_HOLIDAYS.
    T_DATE = SOURCE_FIELDS-/BIC/ZCCCHP812.
    P_DATE = SOURCE_FIELDS-/BIC/ZCCCHP810.
    CALL FUNCTION 'HOLIDAY_GET'
    EXPORTING
    HOLIDAY_CALENDAR = 'CH'
    FACTORY_CALENDAR = 'CH'
    DATE_FROM = P_DATE
    DATE_TO   = T_DATE
    TABLES
    HOLIDAYS = IT_HOLIDAYS
    EXCEPTIONS
    FACTORY_CALENDAR_NOT_FOUND = 1
    HOLIDAY_CALENDAR_NOT_FOUND = 2
    DATE_HAS_INVALID_FORMAT = 3
    DATE_INCONSISTENCY = 4
    OTHERS = 5.
    DESCRIBE TABLE IT_HOLIDAYS LINES CNT.
    X_DATE = T_DATE - P_DATE - CNT.
    RESULT = X_DATE.
    Please help
    Regards
    Zabina
    Edited by: Syed786 on Nov 2, 2011 9:15 AM

    Hi Zabina,
    Try this function module  'DURATION_DETERMINE'.
    Give the factory calendar and unit as DAY
    With regards,
    Rajesh

Maybe you are looking for

  • Help! My boss wants to Save as Excel!

    My boss wants our application to be able to save data directly from our application to multiple file types, this includes Excel, word.... etc, basically every type that the windows SaveAs functionality allows. Is this even possible? Even if I can not

  • Is my airport network secure with Personal File Sharing on?

    I have my Airport Extreme connected to a cable modem. I have a G4 tower w/external hard drive connected by ethernet cable to the airport base station. I use a MacBook laptop wirelessly around the house to access the internet. Each computer is set up

  • HT203167 I downloaded a movie n now can't find it? This was on my iPad

    I downloaded a movie and now can not find it. This was on my iPad.

  • Is there a way to goto SE38 using a Function module

    Hello Friends, I don't have authorisation to SE38 in dev system. But I need it to check something. Is there a way to goto SE38 using a Function module. I know that one of my ABAP friends had done this long back. This will be very helpful. Thanks Simm

  • Tweened drop down box?

    Hi all, I'm looking to hve a website where there are a series of tabs along the top (which i have images for), which will drop down on mouseover, and rise back up on mouse out, only leaving the bottom of the image showing (idea being that they are bu