Diff between two timestamp in minutes on case condition

Hi Gurus,
I wanted to find the diff between two timestamp in minutes on case condition
when type=1 then min(col2) and type=2 then max(col2)
type-(datatype-numeric)
col2-(datatype-timestamp)
how can i do this
Thanks

Hi,
Is this a question about the Berkeley DB SQL product?
If so, you should look at the documentation on time fields in the SQLite page here:
http://www.sqlite.org/datatype3.html#datetime
Otherwise, you are asking this on the wrong forum.
Regards,
Alex Gorrod
Oracle Berkeley DB.

Similar Messages

  • Diff in two timestamp in minutes

    Hi Gurus,
    I wanted to find the diff between two timestamp in minutes on case condition
    when type=1 then min(col2) and type=2 then max(col2)
    type-(datatype-numeric)
    col2-(datatype-timestamp)
    how can i do this
    Thanks

    Im guessing you want like bleow
    time-----------------type--------------------diff
    10/11/2010-------1-----------------------10/23/2010minus10/12/2010
    10/23/2010--------1---------------------10/23/2010minus10/12/2010
    10/12/2010---------2---------------------10/23/2010minus10/12/2010
    10/04/2010---------2----------------------10/23/2010minus10/12/2010
    is it correct?

  • Timestamp in minutes on case condition

    Hi Gurus,
    I wanted to find the diff between two timestamp in minutes on case condition
    when type=1 then min(col2) and type=2 then max(col2)
    type-(datatype-numeric)
    col2-(datatype-timestamp)
    how can i do this
    Thanks

    Hi,
    Sorry, the question could means diozens of different things.
    This is the answer to one of them:
    SELECT     id
    ,       ...   -- other columns from individual rows
    ,     MAX ( CASE
                WHEN  type = 2
                THEN     col2
               END
             ) OVER (PARTITION BY  id)
          -     MIN ( CASE
                WHEN  type = 1
                THEN     col2
               END
             ) OVER (PARTITION BY  id)     AS dif
    FROM    table_x
    ;The dif column will be an INTERVAL DAY TO SECOND., which you can convert to a number if you need to.
    Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data. Explain how you get those results from that data.
    Always say what version of Oracle you are using.

  • Difference between two timestamp.

    Hi,
    I want to find difference between two timestamp in minutes.
    Actually i want to retrieve difference between current timestamp and the timestamp taken from the table
    select log_time from serv_info where server_id = 1;
    Can anyone tell me the query to find difference between two timestamps in minutes.
    -haifriends

    SQL> WITH serv_in AS
         (SELECT SYSTIMESTAMP - 1 / 4 log_time,
                 SYSTIMESTAMP now
            FROM DUAL)
    SELECT log_time,
           now,
             24 * 60 * EXTRACT (DAY FROM (now - log_time))
           + 60 * EXTRACT (HOUR FROM (now - log_time))
           + EXTRACT (MINUTE FROM (now - log_time))
           + 1 / 60 * EXTRACT (SECOND FROM (now - log_time)) diff_in_minutes
      FROM serv_in
    LOG_TIME  NOW                                 DIFF_IN_MINUTES
    01-MRZ-07 01-MAR-07 03.47.42.107462 PM +01:00      360,001791

  • 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

  • How can I make a server differ between two or more clients?

    How can I make a server differ between two or more clients?
    The clients can connect and talk to the server fine, but how can I make the server talk to one, two or all clients? i.e. what would be a good way to implement this?
    Currently, the server listens for connections like this:
    while (listening) {
    try {
    new ServerThread(this, serverSocket.accept()).start();
    I guess one way would be to add the ServerThreads to a Hashtable with the client ID as key, and then get the ServerThread with the proper client ID, but this seems unnecessary complicated. Any ideas?

    Complicated was perhaps the wrong word, I should have
    written something like it doesn't "feel" right. Or is
    this a common and good way to solve communication
    between a server and multiple clients?Thats pretty much how I do it. I normally use an array or ArrayList of Sockets instead of HashTable, with [0] being the first player etc.... Then you can communicate with exactly who you want. If you want to send bytes to all of them, just send the same thing to each socket individually (or is there a better way to do this?).

  • 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

  • Need a sql query to get the difference between two timestamp in the format of hh:mm:ss.msec

    I have a database table where it keeps record of the transaction when it starts at StartTime and when it ends at EndTime. Both these entries are having the timestamp entries. Say for example, I have a tuple with Entries like 'Transaction A' starts at '2014-05-07
    20:55:03.170' and ends at '2014-05-08 08:56:03.170'. I need to find the difference between these two timestamps and my expected output is 12:01:00.000. Let me know how to achieve this ? 

    Hi,
    You can use below script which calculates difference as DD:HH:MM:SS. You can modify the same:
    DECLARE @startTime DATETIME
    DECLARE @endTime DATETIME
    SET @startTime = '2013-11-05 12:20:35'
    SET @endTime = '2013-11-10 01:22:30'
    SELECT [DD:HH:MM:SS] =
    CAST((DATEDIFF(HOUR, @startTime, @endTime) / 24) AS VARCHAR)
    + ':' +
    CAST((DATEDIFF(HOUR, @startTime, @endTime) % 24) AS VARCHAR)
    + ':' +
    CASE WHEN DATEPART(SECOND, @endTime) >= DATEPART(SECOND, @startTime)
    THEN CAST((DATEDIFF(MINUTE, @startTime, @endTime) % 60) AS VARCHAR)
    ELSE
    CAST((DATEDIFF(MINUTE, DATEADD(MINUTE, -1, @endTime), @endTime) % 60)
    AS VARCHAR)
    END
    + ':' + CAST((DATEDIFF(SECOND, @startTime, @endTime) % 60) AS VARCHAR),
    [StringFormat] =
    CAST((DATEDIFF(HOUR , @startTime, @endTime) / 24) AS VARCHAR) +
    ' Days ' +
    CAST((DATEDIFF(HOUR , @startTime, @endTime) % 24) AS VARCHAR) +
    ' Hours ' +
    CASE WHEN DATEPART(SECOND, @endTime) >= DATEPART(SECOND, @startTime)
    THEN CAST((DATEDIFF(MINUTE, @startTime, @endTime) % 60) AS VARCHAR)
    ELSE
    CAST((DATEDIFF(MINUTE, DATEADD(MINUTE, -1, @endTime), @endTime) % 60)
    AS VARCHAR)
    END +
    ' Minutes ' +
    CAST((DATEDIFF(SECOND, @startTime, @endTime) % 60) AS VARCHAR) +
    ' Seconds '
    Reference:
    http://sqlandme.com/2013/12/23/sql-server-calculating-elapsed-time-from-datetime/
    - Vishal
    SqlAndMe.com

  • To calculate elapsed time between two timestamp attributes

    Hello,
    I have two timestamp attributes (create_tmstmp & elapsed_tmstmp) in a table.
    It has two rows and I need the difference in seconds between these two attributes.
    The below query is returning negative value and incorrect value.
    Any help is appreciated.
    Row 1:
    Create_tmstmp : 2/2/2010 9:53:15.832 PM
    Elapsed_tmstmp : 2/3/2010 9:49:47.527 AM
    Row 2:
    Create_tmstmp : 2/3/2010 5:35:47.614 AM
    Elapsed_tmstmp : 2/3/2010 11:03:15.937 AM
    Select
    ( (extract(day from elapsed_tmstmp )-extract(day from create_tmstmp))*86400+
    (extract(hour from elapsed_tmstmp )-extract(hour from create_tmstmp))*3600+
    (extract(minute from elapsed_tmstmp)-extract(minute from create_tmstmp))*60+
    (extract(second from elapsed_tmstmp)-extract(second from create_tmstmp))*1000) completed_tmstmp
    From table_a;
    The output is :
    completedtmstmp_
    74655
    -11997
    Thanks.
    Edited by: solsam on Feb 4, 2010 11:57 AM

    hi,
    The problem with cast to date is
    SQL> select to_char(cast(to_timestamp('2/2/2010 9:53:15.832 PM','mm/dd/yyyy hh:mi:ss.ff pm') as dat
    e),'mm/dd/yyyy hh:mi:ss pm') from dual
    2 ;
    TO_CHAR(CAST(TO_TIMEST
    02/02/2010 09:53:16 pm
    so cast rounds it up, resulting in:
    SELECT (
    CAST (TO_TIMESTAMP ('2/2/2010 9:53:15.832 PM', 'mm/dd/yyyy hh:mi:ss.ff pm') AS DATE)
    - CAST (TO_TIMESTAMP ('2/2/2010 9:53:14.432 PM', 'mm/dd/yyyy hh:mi:ss.ff pm') AS DATE)
    * 86400 x
    FROM DUAL
    X
    2
    A more exact answer would use, to_char and to_date to convert :
    SELECT (
    TO_DATE (TO_CHAR (TO_TIMESTAMP ('2/2/2010 9:53:15.832 PM', 'mm/dd/yyyy hh:mi:ss.ff pm'),
    'mm/dd/yyyy hh:mi:ss pm'),
    'mm/dd/yyyy hh:mi:ss pm')
    - TO_DATE (TO_CHAR (TO_TIMESTAMP ('2/2/2010 9:53:14.432 PM', 'mm/dd/yyyy hh:mi:ss.ff pm'),
    'mm/dd/yyyy hh:mi:ss pm'),
    'mm/dd/yyyy hh:mi:ss pm')
    * 86400 x
    FROM DUAL
    X
    1
    Edit:
    Massimo Ruocchio's answer actually works better.
    -AC
    Edited by: user12026137 on Feb 9, 2010 12:45 PM

  • Oracle-java How to fetch data between two Timestamps

    hai...
    I am using a program where i have to get all the data entered into oracle db between two dates
    (The first date being manually inputted and the second one is inputdate-24hrs) . The code is as follows....
    Connection c = null;
    PreparedStatement pStmt = null;
    ResultSet rs = null;
    try
    //eg  String dt=14/03/2007, hr=03, min=27, ampm=am
         DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
         DateFormat outForm = new SimpleDateFormat("yyyy/MM/dd");
         Calendar cl = Calendar.getInstance();
         Date inDate = new Date();
         inDate = dateFormat.parse(dt);
         cl.setTimeInMillis(inDate.getTime());
         cl.add(Calendar.DAY_OF_MONTH, -1);
         String str1 = outForm.format(new Date(cl.getTimeInMillis()));
         String str2 = outForm.format(dateFormat.parse(dt));
         System.out.println("Changed date = "+str1);
         System.out.println("Original date = "+str2);
         String toStr = str2+" "+hr+":"+min+" "+ampm.toUpperCase();
         String fromStr = str1+" "+hr+":"+min+" "+ampm.toUpperCase();
         System.out.println("From date = "+fromStr);
         System.out.println("To date = "+toStr);
    // For example, if u r confused, From date = 2007/03/14 03:27 AM
    //                            To date = 2007/03/13 03:27 AM
         String sql = "SELECT TRANS_ID, TO_CHAR(CONCAT('Rs.',TRANS_VALUE)) AS TRANS_VALUE, " +
                   "TO_CHAR(TRANS_DATE,'DD/MM/YYYY HH:MM AM') AS TRANS_DATE, ACCOUNT_ID,  " +
                   "TO_CHAR(CREATED_DATE,'DD/MM/YYYY HH:MM AM') AS CREATED_DATE, CREATED_BY, " +
                   "INSTR_D_BANK_CD FROM TRANS_TB WHERE " +
                   "ACCOUNT_ID=? AND TO_CHAR(TRANS_DATE,'YYYY/MM/DD HH:MM AM') " +
                   "BETWEEN ? AND ? ;
         c=ds.getConnection();
         pStmt = c.prepareStatement(sql);
         pStmt.setString(1, accountId);
         pStmt.setString(2, fromStr);
         pStmt.setString(3, toStr);               
         rs = pStmt.executeQuery();     
    }The problem is that i am not getting results as expected
    Can anyone point out if there is something wrong in the logic or in the program....

    But how to make that string to the Timestamp object.
    I tried this way but failed !!!
    // Eg :fromStr = 2007/03/14 03:27 AM
    //       toStr= 2007/03/13 03:27 AM
         SimpleDateFormat sdfOutput = new SimpleDateFormat("yyyy/MM/dd hh:mm a");
         Date fromDate = sdfOutput.parse(fromStr);
         Date toDate = sdfOutput.parse(toStr);
    SELECT TRANS_ID, TO_CHAR(CONCAT('Rs.',TRANS_VALUE)) AS TRANS_VALUE, " +
                   "TO_CHAR(TRANS_DATE,'DD/MM/YYYY HH:MM AM') AS TRANS_DATE, ACCOUNT_ID,  " +
                   "TO_CHAR(CREATED_DATE,'DD/MM/YYYY HH:MM AM') AS CREATED_DATE, CREATED_BY, " +
                   "INSTR_D_BANK_CD FROM TRANS_TB WHERE " +
                   "ACCOUNT_ID=? AND TRANS_DATE BETWEEN ? AND ? ;
    //Eg TRANS_DATE = "11-MAR-07 12.30.59.729000000 PM"(Timestamp)
    c=ds.getConnection();
         pStmt = c.prepareStatement(sql);
         pStmt.setString(1, accountId);
         pStmt.setString(2, fromDate);
         pStmt.setString(3, toDate);               
         rs = pStmt.executeQuery();     
         I think there is problem in both String-Date conversion and in the query.....

  • How to get the time difference (in seconds) between two timestamp fields?

    Hi All,
    I'm exploring validation expressions in SAP MDM Data Manager version 7.1.07.245
    I have two timestamp fields, suppose Update Date and Update-GDS.
    What I'm trying to do is prompt a warning when:
    (Update Date minus Update-GDS) is greater than or equal to zero seconds
    AND
    (Update Date minus Update-GDS) is less than or equal to 900 seconds
    the bottomline is, Update Date must be equal or greater than to Update-GDS but Update Date must not exceed 900 seconds difference.
    my initial try was:
    (Update Date - Update-GDS)>=0 s AND (Update Date - Update-GDS)<=900 s
    But it always returns true even the time difference between update date and update-gds is beyond the condition.
    Can you please guide me through this?
    Thank you very much in advance.
    Regards,
    ~erwin

    Hi Abhishek,
    I tried your code but it always returns true.
    It seems subtraction of timestamp fields do not actually get the time difference... (in seconds)
    Is this possible anyway? Or is there any other better approach on this?
    Thanks,
    ~erwin
    Edited by: erwin.j.rivera on Dec 14, 2011 8:40 AM

  • Best way to get different between two timestamp

    Hi all is a simple question?
    I want the different in days between 2 timestamp.
    The timestamp can be of different year.
    Any solution?

    pedriky wrote:
    Can be a solution form many situation?
    long difMil = new Long( (timestamp1.getTime() - timestamp.getTime())+"");
    int milxday = 24 * 60 * 60 * 1000;
    difMil= difMil / milxday;Why the incredibly messy subtraction?
    What's wrong with:
    long difMil = timeStamp1.getTime() - timeStamp.getTime();
    int days = (int)((difMil + 12 * 3600000L) / (24 * 3600000L));NB, if you don't round your division you can get problems where daylight saving time shifts the start of the interval forward an hour.

  • 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

  • Difference between two dates in minutes

    Hi
    I have two fields two date fields in database DATECALLED and CLOSE_DATE both are declared as DATE fields within the table.
    Both of these fields use : Date Picker (DD-MM-YYYY HH24:MI)
    When I look at the entered date it shows the current time also (when viewed in the data picker control)
    I want to have a chart that displays the difference between DATECALLED and CLOSE_DATE in minutes.
    How do I go about doing this?
    Thanks
    Adam

    subtract one from the other and multiply by 1440.

  • How to find the difference between two timestamp column

    Dear All,
    please Solve my issue,
    I have Table name Record which has the following columns,
    Empid in number column, dat in timestamp
    which has the following values
    Expand|Select|Wrap|Line Numbers
    empid dat
    ====== ====
    101 4/9/2012 9:48:54 AM
    101 4/9/2012 9:36:28 AM
    101 4/9/2012 6:16:28 PM
    101 4/10/2012 9:33:48 AM
    101 4/10/2012 12:36:28 PM
    101 4/10/2012 8:36:12 PM
    101 4/11/2012 9:36:28 AM
    101 4/11/2012 4:36:22 PM
    Here I need to display the following columns,
    empid,min(dat) as start,max(dat) as end and difference(max(dat)-min(dat) for each day,
    for eg,
    Empid Strart end difference
    101 4/9/2012 9:48:54 AM 4/9/2012 6:16:28 PM 8.28
    like this.
    Here 3 different days are exists so It should return 3 records with the above mentioned columns,
    Please Help me to get this.
    Thank you,
    Regards,
    Gurujothi
    Edited by: Gurujothi on Apr 25, 2012 4:45 AM

    >
    101 4/9/2012 9:48:54 AM 4/9/2012 6:16:28 PM 8.28
    >
    why 4/9/2012 9:48:54?
    why not 4/9/2012 9:36:28 AM ?
    SQL>
    SQL> with t as
      2  (select  101 empid, to_timestamp('4/9/2012 9:48:54 AM', 'dd/mm/yyyy hh:mi:ss AM') dat from dual union all
      3  select 101, to_timestamp('4/9/2012 9:36:28 AM', 'dd/mm/yyyy hh:mi:ss AM') dat from dual union all
      4  select 101, to_timestamp('4/9/2012 6:16:28 PM', 'dd/mm/yyyy hh:mi:ss PM') dat from dual union all
      5  select 101, to_timestamp('4/10/2012 9:33:48 AM', 'dd/mm/yyyy hh:mi:ss AM') dat from dual union all
      6  select 101, to_timestamp('4/10/2012 12:36:28 PM', 'dd/mm/yyyy hh:mi:ss PM') dat from dual union all
      7  select 101, to_timestamp('4/10/2012 8:36:12 PM', 'dd/mm/yyyy hh:mi:ss PM') dat from dual union all
      8  select 101, to_timestamp('4/11/2012 9:36:28 AM', 'dd/mm/yyyy hh:mi:ss AM') dat from dual union all
      9  select 101, to_timestamp('4/11/2012 4:36:22 PM', 'dd/mm/yyyy hh:mi:ss PM') dat from dual
    10  )
    11  select empid, min(dat) as start_dat
    12  , max(dat) as end_dat
    13  , max(dat)-min(dat) diff
    14  from t
    15  group by empid, trunc(dat)
    16  /
         EMPID START_DAT                                         END_DAT                                           DIFF
           101 04.09.12 09:36:28,000000000                       04.09.12 18:16:28,000000000                       +000000000 08:40:00
           101 04.11.12 09:36:28,000000000                       04.11.12 16:36:22,000000000                       +000000000 06:59:54
           101 04.10.12 09:33:48,000000000                       04.10.12 20:36:12,000000000                       +000000000 11:02:24
    SQL>

Maybe you are looking for

  • How do I add a Handwritten Signature to my form? And other Form Questions

    Hi there, I'm making a form for parents who's kids are going to drive a motorcycle for the first time. Now I want to use my laptop with touchscreen for people to fill it in. the normal boxes (name, adres etc) with keyboard. But the important part is

  • Query to get the name of the tables used in a View?

    Hi, Could you please help me in getting the name of the tables used in a perticular view? Please help me out... thnx in advance. Thnx, Bits Edited by: Bits on Sep 14, 2009 2:15 PM

  • Retrieve the default content access account for search through code

    Hi there,        Does anyone have the code to retrieve the default content access account (crawl account) for the MOSS search? I tried looking into Microsoft.Sharepoint.Search.Adminstration.SearchService namespace. It has a "crawlaccount" property bu

  • RemoteFX: Guest OS Driver Unknown

    Installed a Sapphire AMD FirePro V5900 GPU in a HyperVisor server with a Xeon E5504 and running Windows Server 2008 R2 Standard, so the HyperVisor is working and Hyper-V manager recognizes and attaches the RemoteFX 3D Video adapter to the guest VM co

  • View photos full screen

    Just updated ATV to 2.1, now the only way to view the photos in full screen is with the Ken Burns effect on. I've seen some older post that say you have to have it on to view in full screen. I like the Ken Burns effect but only when I have control. B