Subtract Time  from Time

Dear Sir,
I want to subtract Time from time, Please help me
SELECT A.EMP_CODE,
TO_DATE(A.INTIME,'DD/MM/RR')IN_DATE
,MIN(TO_CHAR(A.INTIME,'HH24:MI')) IN_TIME
,MAX(TO_CHAR(A.OUTTIME,'HH24:MI')) OUT_TIME
,TRUNC(SUM(A.TDAYS)*24)||':'||TRUNC((SUM(A.TDAYS)*24-TRUNC(SUM(A.TDAYS)*24))*60) TOTAL_TIME
FROM HCM.EINOUT A, HCM.PERSONNEL B
     WHERE A.EMP_CODE = B.EMP_CODE AND
     TO_DATE(A.INTIME,'DD/MM/RR')BETWEEN
     TO_DATE('01/08/12','DD/MM/RR') AND TO_DATE('15/08/12','DD/MM/RR')
     AND B.DEPT_CODE = 16 and a.emp_Code = '09833'
     GROUP BY A.EMP_CODE, TO_DATE(A.INTIME,'DD/MM/RR')--, a.tdays
     ORDER BY 1, 2 ASC;
I want to subtract 20:00 from (out_time) column from every record
If I subtract it from first record then result in over_time column will be 2:46
(out_time - 20:00)
--------------Out put........................
code date in_time out_time total_time over_time
09833     02-AUG-12     09:18     22:46     13:28
09833     03-AUG-12     09:16     21:50     12:34
09833     04-AUG-12     09:28     21:41     12:13
thanks

this will help
--And if difference can be > 24 hours:
WITH t AS
     (SELECT TO_DATE ('26-aug-2011 10:10:10',
                      'dd-mon-yyyy hh24:mi:ss'
                     ) start_date_time,
             TO_DATE ('26-aug-2011 10:12:10',
                      'dd-mon-yyyy hh24:mi:ss'
                     ) end_date_time
        FROM DUAL)
SELECT    TRUNC (end_date_time - start_date_time)
       || ' days '
       || TO_CHAR (TRUNC (SYSDATE) + (end_date_time - start_date_time),
                   'hh24:mi:ss'
                  ) time_diff
  FROM t
--Or interval based solution for < 24 hour diff:
WITH t AS
     (SELECT TO_DATE ('26-aug-2011 10:10:10',
                      'dd-mon-yyyy hh24:mi:ss'
                     ) start_date_time,
             TO_DATE ('26-aug-2011 10:12:10',
                      'dd-mon-yyyy hh24:mi:ss'
                     ) end_date_time
        FROM DUAL)
SELECT REGEXP_SUBSTR (NUMTODSINTERVAL (end_date_time - start_date_time, 'day'),
                      '\d\d:\d\d:\d\d'
                     ) time_diff
  FROM t
--interval based solution for >= 24 hour diff:
WITH t AS
     (SELECT TO_DATE ('26-aug-2011 10:10:10',
                      'dd-mon-yyyy hh24:mi:ss'
                     ) start_date_time,
             TO_DATE ('26-aug-2011 10:12:10',
                      'dd-mon-yyyy hh24:mi:ss'
                     ) end_date_time
        FROM DUAL)
SELECT REGEXP_REPLACE (NUMTODSINTERVAL (end_date_time - start_date_time,
                                        'day'),
                       '^.0*(\d+) (.{8}).+$',
                       '\1 days \2'
                      ) time_diff
  FROM t
--another method
SELECT    TO_CHAR (TRUNC (nb_sec / 3600), '00')
       || ':'
       || TO_CHAR (nb_min - TRUNC (nb_sec / 3600) * 60, '00')
       || ':'
       || TO_CHAR (MOD (nb_sec, 60), '00')
  FROM (SELECT (end_date_time - start_date_time) * 24 * 3600 nb_sec,
               (end_date_time - start_date_time) * 24 * 60 nb_min
          FROM ps_tb_ln_pdc_status_log)
--another method
SELECT SYSDATE + 3.45 / 24 AS "End Date", SYSDATE AS "Start Date",
       CAST (SYSDATE + 3.45 / 24 AS TIMESTAMP) - SYSDATE AS "Duration"
  FROM DUAL;Regards,
friend.

Similar Messages

  • How to subtract time from dateTime in xquery?

    How to subtract time from dateTime in xquery??
    In ALDSP i tried to use the function xf:add-days but it is showing an error saying invalid function name. I think this namespace is not valid for ALDSP. Is there is any way to add this function in ALDSP???

    xquery functions and operators documentation is here :
    http://www.w3.org/TR/xpath-functions/
    It sounds like you want to ..
    op:subtract-dayTimeDuration-from-dateTime
    this is not an xquery function that you can call, it is an xquery operation defined by the specification
    I believe you can simply use the '-' operator to use that operation.
    <newDateTime>
    { $myDateTime - $myTime }
    </newDateTime>

  • How to subtract Time from Sysdate

    Hello,
    I want to subtract time from sysdate and get the sysdate with time.
    Example : = (Sysdate with time)03-mar-2002 16:40:55 - 8 (hours). The result should be like :03-mar-2002 08:40:55
    How to write a query for this?.
    Please let me know as soon as possible.
    Thanks,
    Ravi.

    Hi Ravi...
    SYSDATE includes time, TRUNC(SYSDATE) does not include time.
    If you subtract these two, you'll get a positive number of 1.00 or less which is the fraction of a day. For instance high noon would have a fraction of 0.50000. 12:01 p.m. would be 0.50000 + (1/(24*60)), or 0.50069444....
    If you want to set the clock back, by calculating a "date" that is 8 hours less than the SYSDATE, then SYSDATE - (8/24) will do that. This will work even if SYSDATE was something like 2 a.m., because it will then set it to 6 p.m. of the day before the day in SYSDATE.
    If you want to set a "date" to a specific time on the day of SYSDATE, then calculate the fraction for that time and add it to the TRUNC(SYSDATE). High noon would be TRUNC(SYSDATE) + 0.5.
    SELECT TO_CHAR(TRUNC(SYSDATE)+0.5,'DD-MON-YY HH:MI:SS am') AS NOON FROM DUAL;Hope this helps...
    Larry Johnson

  • SUBTRACT TIME FROM DATE & TIME

    Hi.
    I need FM which will SUBTRACT TIME from DATE & TIME.
    Example:
    Date = 05.05.2007
    Time = 05:00:00
    Time_subtract = 48:00:00
    Return of FM:
    Date = 03.05.2007
    Time = 05:00:00
    Do you know any FM?
    Thanks!

    Hi, Check these function mod's
    SD_DATETIME_DIFFERENCE
    HRCM_TIME_PERIOD_CALCULATE
    HR_ECM_GET_PERIOD_BETW_DATES
    After you execute them in SE37 give the required input and you will get a correct output.
    <b>REWARD IF USEFUL</b>
    thanks n regards
    Dinesh

  • SUBTRACT TIME TO DATE & TIME

    Hi.
    I need SUBTRACT TIME TO DATE & Time.
    Example:
    Date = 08.05.2007
    Time = 01:00:00
    Time_subtract = 2:00:00
    Return of FM:
    Date = 07.05.2007
    Time = 23:00:00
    Do you know any FM?
    Thanks!

    Since the max time difference can be 24 hrs you can reduce that much amount of time from the initial date and then add the difference from the initial date.
    Example : if time difference is to be calculated is 05:00:00 , since this is less than 24 , just add 24 -5 hrs = 19 hrs to the date ( subtract 1 from initial date ) using CONV_UTIL_ADD_DATE_AND_TIME.
    If time to be added is greater than 24 hrs then subtract ( TIME/24 ) from original date and add the difference to date.
    Example : 
    Date = 08.05.2007
    Time = 01:00:00
    Time_subtract = 52:00:00
    Subtract figure = 52/24 = 3 , 52 - 48 = 4.
    Return of FM:
    New date :
    Date = 05.05.2007
    Time = 01:00:00
    Now add 4 to above date using FM to get result.

  • Trying to subtract days from a date

    Im trying to subtract days from a date.
    When i use this query:
    select sysdate-:p21_DAYS_OLD from dual;
    it displays the correct date but not in the correct format. It is displaying 12-AUG-09 instead of 08/12/2009.
    I tried this query but i get the ORA-01722: invalid number error.
    select to_char(sysdate,'MM/DD/YYYY')-(:p21_DAYS_OLD) from dual;
    Can someone help me please?
    Deanna

    Dclipse03 wrote:
    Im trying to subtract days from a date.
    When i use this query:
    select sysdate-:p21_DAYS_OLD from dual;Just set the NLS_DATE_FORMAT parameter for your session and execute the above query.
    ALTER SESSION SET NLS_DATE_FORMAT='MM/DD/YYYY'
    /

  • Subtracting Days from a Date

    Am using Acrobat Pro 9 for Windows.  I have a form where I want to subtract days from Date1 and the result is Date2.  The Date1 and Date 2 text boxes are unformatted.  I've tried reading the "date" articles and experimental with some formulas but I'm afraid I'm still Acrobat illiterate.  Any ideas?  Thanks.

    It would be best if you set up the Date1 field to be formatted as a date. That way, Acrobat uses a built-in routine to automatically validate that the entry represents a valid date. You can then use a custom Calculate script for the Date2 field that looks someting like:
    // Custom Calculate script for text field
    (function () {
        // Get Date1 field value
        var v = getField("Date1").value;
        // If field is empty, blank this field
        if (v === "") {
            event.value = v;
            return;
        // Convert the date string to a date object
        var d = util.scand("mm/dd/yyyy", v);
        // Subtract 5 days
        d.setDate(d.getDate() - 5);
        // Set this field's value
        event.value = util.printd("mm/dd/yyyy", d);
    Change the date format (mm/dd/yyyy) in the code above to match what you want to use.

  • Subtracting sysdate from parameter

    All,
    I need to have user input parameter value.
    for example i want to restrict query based on input parameter.
    I have created a paramter as old_report where user would enter number of days they want to go back and see reports for.
    So my where condition is
    Receipt_date <=TRUNC(SYDATE)- :Old_report.
    whenever i tried to enter value it fails with error wrong value '5' for paramter
    Looking at documents it says that it requires same datatype with reserved words.
    SYSDATE being reserverd words how do i convert numeric values to date format?
    Any one please help.
    Thanks

    Hi
    This should work, you need to convert the value received from the parameter into a number. By default all parameters associated with <NONE> are strings.
    Let's assume that receipt_date is a date and that it is truncated, then this algorithm, receipt_date <= TRUNC(SYSDATE) will return all receipts.
    Taking your example, let's say we have a parameter called START_DAYS and the user keys 5. This alogrithm, receipt_date <= (TRUNC(SYSDATE) - to_number(START_DAYS)) will only return receipts that have dates five days in the past.
    You need to teach your users to only key numbers otherwise this will fail because to_number('A') will not compute. Of course you ought to trap NULL values and negative numbers too, which the following will do. We trap negative numbers so that dates don't end up in the future. This algorithm uses zero for NULL and negative values, essentially subtracting nothing from the system date.
    RECEIPT_DATE <= TRUNC(SYSDATE) - DECODE(SIGN(TO_NUMBER(NVL(START_DAYS,0))),-1,0,TO_NUMBER(NVL(START_DAYS,0)))
    Hope this helps
    Regards
    Michael

  • Subtracting months from current date

    how to subtract months from current date in mysql

    You are in an Oracle forum, so the Oracle answer is: use add_months(sysdate,-2) to subtract two months from the current date.
    Regards,
    Rob.

  • Subtract minutes from system time

    Hi Experts,
    I want to subtract 5 min from the system time.
    Is there any function module.
    Regards,
    Chandu

    Hi Chandu,
    Use the below statment to subtract 5 minutes:
    data: v_time type sy-uzeit.
    v_time = sy-uzeit.
    v_time  = v_time - 300.
    This might solve your problem.
    Thanks,
    Chidanand

  • Formula for subtracting time from a datetime field

    I have a field that is formatted as a datetime field. I just need to know how to subtract 3.5 hours from this time. How do I write a formula in crystal reports kindly help me.
    Thanks in advance
    Ramakrishna Reddy

    This should do the trick...
    DateAdd("n", -210, {TableName.DateField})
    HTH,
    Jason

  • Subtracting time end from time start

    I'm trying to get end time subtracted from start time
    Here is the query:
    SELECT TO_CHAR(service_end,'HH24:MI:SS') "EOD", TO_CHAR(service_start,'HH24:MI:SS') "SOD"
    FROM response
    So hypothetically (although this won't work), should give me the time
    SELECT (TO_CHAR(service_end,'HH24:MI:SS') - TO_CHAR(service_start,'HH24:MI:SS')) "Total Time"
    FROM response

    Hi,
    If service_start and service_end are DATEs, then
    service_end - service_startwill be a NUMBER, the number of days between them them. For example, if service_end is 6 hours after service_start, that number will be .25.
    Do you want to display that as hours, minutes and seconds?
    If that number is less than 1 (that is, the difference is less than 24 hours) you can dispaly it by adding it to any DATE that has the time 00:00:00, and displaying only the time portion.
    For example:
    SELECT  TO_CHAR ( TRUNC (SYSDATE) + service_end - service_start
                    , 'HH24:MI:SS'
                    )Regardless of how large the number is, you can convert it to a formatted "D HH:MI:SS" format using NUMTODSINTERVAL:
    NUMTODSINTERVAL ( service_end - service_start
                    , 'DAY'
                    )Edited by: Frank Kulash on Jun 5, 2009 1:59 PM
    Added NUMTODSINTERVAL example.

  • Add or subtract minutes from any time of day

    Hello!
    The problem I'm having is that add or subtract minutes related
    to a time stamp like e.g.
    + (plus)
    17:21 timestamp
    minutes to add +80
    result -> 18:41
    - (minus)
    17:21 timestamp
    minutes to subtract -20
    result -> 17:01
    Is any function module existing for such
    cases. What would you recommend to me to
    solve the problem to get really reliable
    time.
    THX
    ilhan ertas

    Hi Ilhan,
    as long as you don't leave the limits of a day (i.e. time getting below zero or above 24 hours), ABAP time calculations will get correct results. Type t (time) fields in expressions involving numeric data types are internally converted into the amount of seconds.
    So you can  add minutes by multiplying by 60 (second per minute) first.
    In a type T field 17:21 is represented internally as 172100. Add 4800 (80 minutes times 60 seconds) will result (internally) to 17 * 60 * 60 + 21 * 60 + 4800 = 67260. And this will be converted to time format 184100.
    See also this SAP online help:
    <a href="http://help.sap.com/saphelp_erp2005vp/helpdata/en/fc/eb334a358411d1829f0000e829fbfe/content.htm">Date and Time Calculations</a>
    Regards,
    Clemens

  • 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

  • Need help assigning range for an integer for subtracting time.

    Ok, so I'm having a little trouble getting this program to work. :x Maybe somebody could give me some help on what to do next. I'm new to Java, and I'm trying to write a program using NetBeans 6.9.1, and I ran into a problem. I'm trying to write a program for a time traveler Marty, who is going back in time. The time is set on a 24 hour clock, so am and pm is not an issue.
    I have the program written, but I'm having trouble with the subtraction of the time. Whenever I do the subtract, and the time traveled back (either in hours, minutes or seconds), is bigger than the current time, I just end up with negative numbers. I don't know how to set the value so it will just recycle through the 24 hours, the 60 minutes, or 60 seconds, instead of giving me negative numbers. Any help would be greatly appreciated. Also, I'm not sure how to make the users input italic. Here is what I got so far.
    package timetravel;
    * @author Jeff
    import java.io.*;
    import java.util.*;
    public class Main {
    * @param args the command line arguments
    public static void main(String[] args) {
    int hours, minutes, seconds, hoursback, minutesback, secondsback;
    Scanner keyboard = new Scanner (System.in);
    System.out.println("Hi Marty!");
    System.out.println("Enter current hour:");
    hours = keyboard.nextInt();
    System.out.println("Enter current minute:");
    minutes = keyboard.nextInt();
    System.out.println("Enter current second:");
    seconds = keyboard.nextInt();
    System.out.println("Enter how many hours you want to travel back");
    hoursback = keyboard.nextInt();
    System.out.println("Enter how many minutes you want to travel back");
    minutesback = keyboard.nextInt();
    System.out.println("Enter how many seconds you want to travel back");
    secondsback = keyboard.nextInt();
    System.out.println("When you arrive, the local time will be " + (hours - hoursback)
    + " hours, " + (minutes - minutesback) + " minutes, and " + (seconds - secondsback)
    + " seconds.");

    Well, basically, here's how I want the program to run
    Example program run:
    Hi Marty!
    Enter current hour: 8
    Enter current minute: 12
    Enter current second: 11
    Enter how many hours you want to travel back: 9
    Enter how many minutes you want to travel back: 36
    Enter how many seconds you want to travel back: 39
    When you arrive, the local time will be: 22 hours, 35 minutes, and 32 seconds
    (program input is written in italic)
    instead of how it runs now
    Hi Marty!
    Enter current hour: 8
    Enter current minute: 12
    Enter current second: 11
    Enter how many hours you want to travel back: 9
    Enter how many minutes you want to travel back: 36
    Enter how many seconds you want to travel back: 39
    When you arrive, the local time will be: -1 hours, -24 minutes, and -28 seconds
    I want it to cycle through the 24 hour clock, so if I travel back in time from 18 (1800 or 6pm) and i want to travel back in time 20 hours, I should get 22 (2200 or 10 pm) instead of -2.
    Same with minutes and seconds, except for it to cycle through 60 instead of 24, since there are 60 minutes in an hour, and 60 seconds in a minute. Also, if the minutes end up being negative, I need it to take away one from the hour spot, and so on for the other ones. Hopefully I explained it well enough... Sorry, I'm new to Java.
    Edited by: halo2jak on Sep 7, 2010 12:24 AM

Maybe you are looking for