Trigger Difference Betwwen Two Time- How?

Hi all, I have One table,
Date format :dd/mm/yyyy
Table name: Time_Calculation
Time1--------------------------Time2----------- Diff_Time
8/9/2006 1:10:57 PM----9/9/2006 1:10:58 PM-----24:00:01
I want to create the trigger that can calculate the diffrence time between time2 and time1(time2-time1) and filed it into Diff_Time. When any one or two field (time1 or time2) is update, the trigger should update the record in Diff_Time.
Diff_Time format is: hh:mm:ss
I hope anybody can help me on how to create the trigger in sql query.
Thanks

SCOTT@demo102> create table trg_diff (d1 date, d2 date, diff varchar2(8));
Table created.
SCOTT@demo102>
SCOTT@demo102> create or replace trigger trg_diff_bui
  2  before insert or update on trg_diff
  3  for each row
  4  begin
  5   if :new.d1 is not null and :new.d2 is not null then
  6      :new.diff:=(trunc(:new.d2-:new.d1)*24)+to_char(trunc(sysdate)+(:new.d2-:new.d1),'HH24')||':'||to_char(trunc(sysdate)+(:new.d2-:new.d1),'MI:SS');
  7   else
  8      :new.diff:=null;
  9   end if;
10  end;
11  /
Trigger created.
SCOTT@demo102>
SCOTT@demo102> show err
No errors.
SCOTT@demo102>
SCOTT@demo102> insert into trg_diff (d1,d2) values ((sysdate-1.52),sysdate);
1 row created.
SCOTT@demo102> insert into trg_diff (d1,d2) values ((sysdate-2.1),sysdate);
1 row created.
SCOTT@demo102>
SCOTT@demo102> select * from trg_diff;
D1                  D2                  DIFF
22/09/2006 04:26:54 23/09/2006 16:55:42 36:28:48
21/09/2006 14:31:42 23/09/2006 16:55:42 50:24:00
SCOTT@demo102>
SCOTT@demo102> update trg_diff set d1=d1-1;
2 rows updated.
SCOTT@demo102>
SCOTT@demo102> select * from trg_diff;
D1                  D2                  DIFF
21/09/2006 04:26:54 23/09/2006 16:55:42 60:28:48
20/09/2006 14:31:42 23/09/2006 16:55:42 74:24:00
SCOTT@demo102> Do care with length of column diff, in case of hours greater than 99...
Nicolas.

Similar Messages

  • Extract Time from date and Time and Need XLMOD Funtion to find the Difference between Two Time.

    X6 = "1/5/15 5:16 AM" & NOW ....................difference by Only Time
    not date
    X6 date and Time will be changing, Its not Constant
                Dim myDateTime As DateTime = X6
                Dim myDate As String = myDateTime.ToString("dd/MM/yy")
                Dim myTime As String = myDateTime.ToString("hh:mm tt")
                Dim myDateTime1 As DateTime = Now
                Dim myDate1 As String = myDateTime1.ToString("dd/MM/yy")
                Dim myTime1 As String = myDateTime1.ToString("hh:mm tt")
    Need to use this function to find the Difference between Two Time. due to 12:00 AM isuue
    Function XLMod(a, b)
        ' This replicates the Excel MOD function
        XLMod = a - b * Int(a / b)
    End Function
    Output Required
     dim dd  = XLMod(myTime - myTime1)
    Problem is myTime & myTime1 is String Need to convert them into Time, Later use XLMOD Funtion.

    Induhar,
    As an addendum to this, I thought I'd add this in also: If you have two valid DateTime objects you might consider using a class which I put together a few years ago
    shown on a page of my website here.
    To use it, just instantiate with two DateTime objects (order doesn't matter, it'll figure it out) and you'll then have access to the public properties. For this example, I'm just showing the .ToString method:
    Option Strict On
    Option Explicit On
    Option Infer Off
    Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles MyBase.Load
    Dim date1 As DateTime = Now
    Dim date2 As DateTime = #1/1/1970 2:35:00 PM#
    Dim howOld As New Age(date1, date2)
    MessageBox.Show(howOld.ToString, "Age")
    Stop
    End Sub
    End Class
    I hope that helps, if not now then maybe at some point in the future. :)
    Still lost in code, just at a little higher level.
      Thanx frank, can use this in Future....

  • Function Module to find the Difference between two times.

    Hi All,
    Wud you plz let me know the Function Module to find the Difference between two times.
    Input Time1( Hours:Minutes) Time2 ( Hours:Minutes)
    Need Output in Hours:Minutes only . ( No seconds Needed )
    Ex :
    Input :
           06:00 to 18:00 Output : 12:00
    and  20:00 to 06:00 Output: 10:00 with +ve sign only. No -ve sign.
    Thanks,
    N.L.Narayana

    check this .
    data : p_timel like sy-uzeit,
           p_timeh like sy-uzeit,
           diff like sy-uzeit,
           di(8) type c .
           p_timel = '200000'.
           p_timeh = '060000'.
           diff = p_timeh - p_timel.
           concatenate diff+0(2) ':' diff+2(2) into di.
           write:/ di.
    also check for this.
           p_timel = '060000'.
           p_timeh = '180000'.
    see if this can be implemented in ur code .
    or else  u can try with  Fm L_TO_TIME_DIFF passing startdate enddate starttime endtime with UOM as MIN
    hope this helps regards,
    vijay

  • How to do find the difference between two time stamps

    Hi all,
    i have a table with 2 columns called GMT time and Local time . so i need to find difference between these two time stamps.
    i tried like this
    select to_date(GMT_TIME,'yyyy-mm-dd hh24:hi:ss')-to_date(LOCAL_TIME,'yyyy-mm-dd hh24:hi:ss') from date_table
    the result is coming as follows ..
    0.291666666667
    i did not under stand the out put.
    In my table GMT_TIME= 2011-06-26 00:00:00 and LOCAL_TIME=2011-06-25 17:00:00 ..
    please help me how to get exact hours between two dates ..
    Thanks
    Sreedhar

    Hi Sreedhar,
    Your output (0.2916666) has the unit day.
    You should multiply with 24 to get the unit hour.
    select ( to_date(GMT_TIME,'yyyy-mm-dd hh24:hi:ss')-to_date(LOCAL_TIME,'yyyy-mm-dd hh24:hi:ss') ) * 24 from date_table;Rgds,
    Tycho

  • Function Module to get the difference between two times.

    Hi All,
    I want to know if there is any function module that gives me the difference between two specified times.
    For Ex: Time 1: 12/01/2007 00:01 A.M
                Time 2: Time 1 - 180 Seconds. This changes the time, also may even change the Date. (As in above situation, the Time 2 will be 11/30/2007 11:58 P.M)
    Could some one please suggest if there is any function module for this case.
    Thanks in Advance.

    Hi, You can use the following function module to calculate the diffrence between to dates in the unit that you want.
    COPF_DETERMINE_DURATION calculates the difference between two dates and time in minutes and hours.
    Parameters:
    EXPORTING
         I_START_DATE "The start date of the time interval
         I_START_TIME "The start time of the time interval
         I_END_DATE   "The end date of the time interval
         I_END_TIME   "The end time of the time interval
         I_UNIT_OF_DURATION "Time unit of the duration if not to be calculated in days.
         Value     =====     Meaning
         ' '     =====     Day (default)
         D     =====     Days
         H     =====     Hours
         MIN     =====     Minutes
         MON     =====     Months
         S     =====     Seconds
         WK     =====     Weeks
         YR     =====     Years
         I_FACTORY_CALENDER     "A factory calender if not using the Gregorian calender
    IMPORTING
         E_DURATION      "Time difference in unit specified.
    Message was edited by:
            Rajesh Soman

  • Difference between two times

    Hi All,
    I have a problem and hope I ll get the answer here,
    Problem:
    I have a form where user enter two different times, now i have to find out the difference between these two times. Its like this let assume user enter time 1 = 21:00:00 And time 2 = 23:01:01, till now it gives me result as[b] 2:1:1 as per my calculation but i want it to be as 02:01:01, hope u got my point.
    If u have any doubt please let me know.
    Thanks in Advance
    Amit

    if Its a string you need to append with '0'. Else send me your calculation.

  • What is difference betwwen two g/l accounts in vkoa

    hi
    what is the difference between two g/l accounts in revenue account determination process
    in vkoa transaction

    Hello Nag,
    The first GL account is basically used for posting revenues. Where as in  most cases the second GL is left blank.
    the second coulmn is used if your busienss requirement has to maintain an Accrual account or deffered revenues i.e. instead of posting revenues directly into the GL account (1st column) they will be maintained in the second column (Accruals/deffered revenues) and will be recognised saperately as they realise.
    For example, in case of periodic and milestone billing - revenues are always sent to the deffered account and are recognised by the end of the period using transaction VF44. only then the deffered amount gets transferred to the actual revenue GL account i.e. the amount gets transferred from 2nd column to the 1st column.
    The applies in the case of rebate agreements also where you have accrued amounts.
    <b>Reward points if helps</b>
    Regards
    Sai

  • Difference between two times in 24 hours format

    need function module for passing two times of 24 hours format

    Hi,
    try this Function Module : SD_CALC_DURATION_FROM_DATETIME
    assign points if helpful
    Thanks
    Prashanth

  • How do I calculate the difference between two times?

    I am so embarrassed by the fact that I can't figure this out.
    Cell B2- 8:00 am
    Cell C2- 10:50 am
    Cell D2- (How do I get this cell to calculate the difference and say 2:50?)
    I know this is probably one of the most basic operations, but for the life of me I can't figure it out. Cells B2 & C2 are formatted for 24 hour clock. But if I tell the system to just subtract the two, I get "0.118". Everything I find on the forum search goes beyond what I need. Can anyone help me?
    Thank you.

    KOENIG Yvan wrote:
    Numbers states clearly in the Help and the PDF Users Guide that it doesn't know a "duration" object but a time one which is restricted to the range 00:00:0 to 23:59:59.
    When I search the U.S. language Numbers User Guide for the word "duration," it is not found.
    What may be more clear: _duration is not available but time is_?
    Once again your response resemble to a rant againt the Help and the User Guide.
    In the Help:
    +date-time Any Numbers date/time value. _While you can choose to display only date or time in a cell, all Numbers date or time values contain both the date and time._+
    Which wording would be more clear and precise?
    TIMEVALUE
    +The TIMEVALUE function converts a date, a time, or a text string to _a decimal fraction of a 24-hour day._+
    Which wording would be more clear and precise?
    TIME
    +The TIME function converts hours, minutes, and seconds into a time format.+
    +TIME(hours, minutes, seconds)+
    +hours: The number of hours _(using a 24-hour clock)._+
    +minutes: The number of minutes.+
    +seconds: The number of seconds.+
    Notes
    +You can specify hour, minute, and second values greater than 23, 59, and 59, respectively. _If the hours, minutes, and seconds add up to more than 24 hours, Numbers subtracts 24 hours repeatedly until the sum is less than 24 hours._+
    Which wording would be more clear and precise?
    In the User Guide:
    page 190
    +date-time Any Numbers date/time value. _While you can choose to display_+
    +_only date or time in a cell, all Numbers date or time values contain_+
    +_both the date and time._+
    +TIME (page 277) Converts a time to a decimal fraction of a 24-hour day.+
    +TIMEVALUE (page 278) Converts a time in a string to a decimal fraction of a 24-hour day.+
    TIME
    +The TIME function converts the specified time to a decimal fraction of a 24-hour day.+
    +TIME(hours, minutes, seconds)+
    +• hours: The number of hours _(using a 24-hour clock)_.+
    +• minutes: The number of minutes.+
    +• seconds: The number of seconds.+
    Notes
    +You can specify hour, minute, and second values greater than 23, 59, and 59,+
    +respectively. _If the hours, minutes, and seconds add up to more than 24 hours,_+
    +_Numbers subtracts 24 hours repeatedly until the sum is less than 24 hours._+
    +You can also specify fractional values for hours, minutes, or seconds.+
    TIMEVALUE
    +The TIMEVALUE function converts a time in a string to a decimal fraction of a 24-hour+
    day.
    TIMEVALUE(date-time)
    +• date-time: A date, a time, or a string in any of the Numbers date and time formats.+
    As you may check, the infos are exactly the same in the Help and in the Guide.
    And I really don't understand how you may find them unclear.
    Yvan KOENIG (from FRANCE lundi 4 août 2008 14:57:36)

  • Help I need to subtract times to find the difference between two times?

    Hello there, I really need help.
    I'm trying to make this attendance tracking system so that when a user enters his or her ID the system wll remember his/her check in time. However I also need to find out either how late the person is or how early to store their over time and late.
    So I get the time by using a timestamp, so I'm left with a timestamp that I store into the db. But the problem comes when trying to compute for the late or over time. To do that I have to get the normal login/checkin time from the employee schedules table in the db and either subtract that time from the checkInTime to compute for how late or subtract the checkIn time from it to find early.
    The thing is, the schedule is stored in datetime format in the db since the db is sql. Also I have no idea on how to subtract the two dates via java. The month, date and year stored in the sql db are just fillers, all I need computed is the time difference of the hours and minutes between the checkInTime and the schedule.
    I've tried to use datediff: SELECT e.employeeNumber, datediff('hh', startTime, checkInTime) as lateTime from employeeschedules e, timandattendance, contractualemployees c where c.scheduleNumber=e.scheduleNumber and t.employeeNumber=c.employeeNumber and t.checkInNumber=1;
    But it keeps on giving out various errors: You have an error in your sql syntax check your manual that corresponds to your sql server version. for the right syntax to use near , checkInTime) as lateTime from employeeschedules e, timandattendance, contractualemployees c where c.scheduleNumber=e.scheduleNumber and t.employeeNumber=c.employeeNumber and t.checkInNumber=1;
    My sql server is My SQL 5.0.5
    Now I'm thinking of useing Gregorian instead, but I don't know how to use Gregorian and dont know the various methods. Can someone tell me what to do, provide some sample codes and references that I can use to accomplish what I need to do?

    NewtonsApple_2 wrote:
    Now I'm thinking of useing Gregorian instead, but I don't know how to use Gregorian and dont know the various methods. Can someone tell me what to do, provide some sample codes and references that I can use to accomplish what I need to do?it may help...
    GregorianCalendar

  • FormCalc Formula to tell the difference between two time fields if they are populated - Help please

    Hi,
    I have a cell (TotalTime1) that references two other time formatted cells (Start1 and Finish 1).
    The below formula is intended to tell the difference between the Start and Finish time if they are populated.
    I had it working without the HasValue condition but the formula was calculating when there was no value in Start1 and Finish1 (due to time format).
    This is the code I do have, it says there is an error near the last line; I am sorry if I post this in the wrong manner, I have not posted on this forum before but here goes:
    if (HasValue (Finish1)  and HasValue (Start1)) then if (Time2Num(Start1.formattedValue, "HH:MM") < Time2Num (Finish1.formattedValue, "HH:MM")) then Abs (Time2Num(Start1.formattedValue, "HH:MM") - Time2Num(Finish1.formattedValue, "HH:MM")) / (60 * 60 * 1000) else 24 - Abs (Time2Num(Finish1.formattedValue, "HH:MM") - Time2Num(Start1.formattedValue, "HH:MM")) / (60 * 60 * 1000) endif 
    Any help would be appreciated.
    Regards Fetachini

    Thanks whyisthisme,
    Your speedy response is greatly appreciated, your support has resolved my issue.
    Many thanks.
    Regards
    Fetachini

  • How can you get songs off your IPAD if you have it on there two times

    I have the same song on my Ipad two times how can I get them off.

    On the page where you have your songs, on the right hand side of the song, swipe your finger to the right and the delete button will appear.  It only takes a quick swipe.  If you hold your finger in on the song first, it will start playing.

  • How Can I minus Two times Time Format is hh24:mi not hh24:mi

    Dear Experts
    I want difference between two times.
    Is It possible?

    Hi,
    What is the data type that you are storing the times in your database?
    If it's date, then Oracle will internally store in it's own format and show the time according to your session's NLS parameters.
    You can simply use date1-date2, which will show the difference in number of days. Hours and minutes are shown in fractions.
    SQL> select sysdate-to_date('20-AUG-1980 15:30:00','DD-MM-YYYY HH24:Mi:SS') age from dual ;
    AGE
    9528.84845
    HTH
    Regards,
    Badri.

  • How to find differene between two time fields??

    Hi Experts,
    I am trying to find difference between two time fields,  I have created two formula variables by using replacement path for the two time fields, I have taken dimension key NUMBER, because of this time format is converting to numbers for example if the time is 13:20:10 then it is converting to 1,32,010 then it is calculating, I am getting wrong values.
    Is there any options to find out the difference between two time fields.
    Thanks in advance,
    Venkat.

    use COPF_DETERMINE_DURATION. Its better you do it in data model itself.
    If you have date and time seperately use command
    use CONVERT TIMESTAMP command and
    then use this function module to get the difference in
    timestamp
    CCU_TIMESTAMP_DIFFERENCE
    us this in conjunction with the below function module
    DAYS_BETWEEN_TWO_DATES
    Edited by: Ananda Theerthan on Jan 21, 2010 7:18 AM

  • Function Module to find the Diff bt Two Times : O/p : Hours:Minutes only

    Hi All,
    Wud you plz let me know the Function Module to find the Difference between two times.
    Input Time1( Hours:Minutes:Seconds) Time2 ( Hours:Minutes:Seconds)
    Need Output in Hours:Minutes only .  ( No seconds Needed )
    Thanks,
    N.L.Narayana

    Hi
    Please use FM
    <b>SD_DATETIME_DIFFERENCE</b>

Maybe you are looking for

  • Not Able to Telnet or SSH Cisco ASA

    Hi, I am not able to do the following to Cisco ASA with one IP address 172.19.1.11, below is the configuration in ASA. Earlier it was working, all of a sudden it stopped working. Please help. 1. Not Able to SSH 2. Solarwinds not able to take informat

  • Problems with the sound in Windows

    Hey everybody, hoping someone can help. I'm working with Cubase in Windows with my mac and i have problems with the sound, but not all the time. I have an M-Audio card connected and while i'm playing something in Cubase, the sound makes a digital dis

  • FM for OTF to TIFF format conversion?

    Hi, Any function module for OTF to TIFF(image file ) format conversion or anything to do it. Thanks Vaibhav

  • Asmcmd "lsdsk -I" doesn't show disks with non-default asm_diskstring

    Hi, I'm testing Oracle 11.1.0.6 on RHEL5 with ASM. It's working well and I'm trying to use the ASM new features but I have the following problem : - When ASM instance is running, I can use "lsdsk" and it shows the disks - When ASM instance is down an

  • KDEmod 4.1 permissions problem

    Hi, I have installed KDEmod 4.1 on my Acer Aspire One and to tell you it's working nicely!!!:D Thanks for the developers who made this...Great Work!! But I have some problems with regards to copying files, etc. I tried changing the permissions on my