Get hours between dates

Hello, I have a problem to obtain the number of hours passed between two dates type dd/mm/yy hh:mm:ss Since of all the day I only must consider the time passed between the 09:00 and the 19:00 of Monday through Friday. Can somebody help me? Thanks.

static final int MILLIS_PER_HOUR = 3600000;
static final int START_OF_DAY = 9 * MILLIS_PER_HOUR;
static final int END_OF_DAY = 19 * MILLIS_PER_HOUR;
public static double hoursBetween(Date d1, Date d2) {
   long midnight = /* 00:00 of the same day */.getTime();
   long msSinceMidnight1 = d1.getTime() - midnight;
   long msSinceMidnight2 = d2.getTime() - midnight;
   // if times fall in "non-countable" hours, adjust them
   if (msSinceMidnight1 < START_OF_DAY) {
      msSinceMidnight1 = START_OF_DAY;
   if (msSinceMidnight2 > END_OF_DAY) {
      msSinceMidnight2 = END_OF_DAY;
   return (double)(msSinceMidnight2 - msSinceMidnight1) / MILLIS_PER_HOUR;

Similar Messages

  • Count number of hours between dates excluding holidays/weekends

    Hello all
    I havent worked with dates extensively and was recently asked to create a report where Im looking for the number of hours between two dates only counting business days.
    So for example I have data as follows
    Created 2011-03-30 15:00:00
    Processed 2011-03-30 15:03:46
    Fulfilled 2011-04-01 17:25:02
    Mailed     2011-04-01 17:45:00
    For a total of looking from the CREATED and MAILED dates
    50 hours 45 minutes
    Im also trying to exclude weekends and holidays, i was reading around and was actually able to also find a table of dates where I have the main date, HOLIDAY_IND column and WEEKDAY_IND column
    So the calender table i have looks similar to
    CALENDER_DATE HOLIDAY_IND WEEKDAY_IND
    2011-03-31 Y Y
    2011-04-01 N Y
    2011-04-02 N N
    Im really quite stumped as to where to begin
    I was thinking of trying to write it with PL/SQL but i dont have the proper user access to create procedures/functions, so looks like straight up SQL
    Any help appreciated!

    Hi,
    Depeneding on your data and your requirements, you can do something like this:
    SELECT     created_DATE,
    ,     mailed_date
    ,     24 * ( (mailed_date - created_date)
                SELECT  COUNT (*)
                FROM        table_o_dates
                WHERE    main_date > created_date
                AND        main_date < TRUNC (mailed_date)
                AND        (   holiday_ind = 'Y'
                         OR  weekday_ind = 'N'
               )               AS hours_between       
    FROM     table_x
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.
    What do you want to do if created_date or mailed_date is not a work day? Include examples in you data and results.

  • Function Module for calculating hours between dates and their times.

    Hi all,
    Is there any standard function module for calculating the time difference in hours between two dates with start and end times.
    Regards,
    Sudipto.

    Sudipto,
    How're you ????????????????????
    Check out the following Function Module:
    SD_DATETIME_DIFFERENCE (Give the difference in Days and Time for 2 dates)
    Regards,
    Abir
    Don't forget to award Points *

  • How to get hour wise data in report?

    Hi gurus,
                  I have one requirement in front end like retrieving data in hour wise suppose like 12.30pm - 4.30pm transaction sales data into the report since i have option to get only up to day wise data. Please do give me the relevant answers where do i need to do change?.
    Thanks
    Bharath

    Hi Saravana
    I am sure you must be getting the values in tables of table parameters from every FM.
    consolidate the values from tables of all FMs in one table and built ALV for that table only.
    I hope this way you can show the actual data in ALV.
    thanks
    Lalit

  • Get number of hours between two dates and two hours using factory calendar

    Hello all,
    I have the following requirement: I need to calculate the number of hours between two dates and two hours (start date- finish date and start hour-finish hour) or timestamps using a factory calendar. I must program it on CRM environment.
    Does anybody know a function module that makes it?
    Thanks in advance.
    Carmen

    Please check function module DURATION_DETERMINE.
    - April King

  • Workflows: How to set a workflow variable that is the difference in hours between now and a created date

    I'm trying to create a variable that contains the number of hours between the item created date and Now.  When i use TODAY, it seems to set the time at 12:00 rather than the time now - so that throws the hours off.  Any ideas?
    ajw

    Hi ajw,
    According to your description, my understanding is that you want to calculate the hours between the item created date and now.
    It seems to be not an OOB way to implement your requirement, to get the current time, you need to create a custom workflow activity for SharePoint 2010 workflow. About creating custom workflow activity, you can refer to the links below:
    http://msdn.microsoft.com/en-us/library/hh872790(v=office.14).aspx
    http://blogs-sharepoint-ashutoshmisra.blogspot.in/2013/02/create-custom-workflow-action-for.html
    Or, you can use a third party solution to achieve your requriement.
    Here are some similar posts for you to take a look at:
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/e93ea37a-df09-4cbf-a58d-5d4def3d3d42/how-to-compare-time-in-sharepoint-designer-2010sp-2010-workflow?forum=sharepointgeneralprevious
    http://blog-sharepoint.blogspot.in/2009/03/get-current-time-in-sharepoint-designer.html
    I hope this helps.
    Thanks,
    Wendy
    Wendy Li
    TechNet Community Support

  • How to calculate Number of Hours between 2 dates

    Hi,
    I have a Column in a table of datatype DATE i.e. Update_Date. Now How do I calculate number of hours passed starting from this date entered in the Update_Date column to SYSDATE. e.g. if the date in column is 2-FEB-2009 and the sysdate is 2/2/2009 2:07:40 AM it should give me 24. How can I get this number of hours.
    Update_Date - Sysdate = Number of Hours.
    Thanks

    When you subtract two dates in Oracle, you get a difference in terms of days. Just multiply that by 24 to get hours.
    SELECT (sysdate - update_date) days,
           (sysdate - update_date) * 24 hours
      FROM your_tableThat said, it is not obvious how your example works. You state
    if the date in column is 2-FEB-2009 and the sysdate is 2/2/2009 2:07:40 AM it should give me 24Since both dates are on February 2, 2009, the only difference is in the time component. If we assume that the time component of the UPDATE_DATE value is midnight since it is not specified, there is a little more than 2 hours of difference between the two dates. How is it that you determine there are 24 hours of difference?
    Justin
    Edited by: Justin Cave on Feb 2, 2009 10:39 AM

  • Getting ORA-01849 hours between 1 & 12

    Hi,
    Hi
    I have a table - audit with the following fields
    org_id number,
    grn_n number,
    ed_eff_m timestamp(6),
    data
    org_grp_i grn_n ed_eff_m
    3 1 07/21/2006 12:21:16 Am
    I want to update ed_eff_m with 07/21/2006 00:00:00
    for the above.
    But when i update the record the record, Iam getting the
    ORA-01849 hours between 1 & 12
    please suggest this update stmt is correct
    update audit ag
    set ed_eff_m= to_date(to_date('07/21/2006 00:00:00','mm/dd/yyyy hh:mi:ss')
    WHERE ag.ORG_GRP_I = 3
    AND ag.GRN_n =1
    Thanks in advance

    If all that is needed is to clear the hour part, you may try this too:
    UPDATE audit_grant_vesting_schedule ag
    SET ag.ed_eff_m = TRUNC(ag.ed_eff_m)
    WHERE ag.ORG_GRP_I = 3
    AND ag.GRN_n = 5633486;
    Hope this helps.

  • 'Get All New Data Request by Request' option not working Between DSO n Cube

    Hi BI's..
             Could anyone please tell me why the option ' Get one Request only' and  'Get All New Data Request by Request' is not working in DTP between Standard DSO and InfoCube.
    Scenario:
    I have done the data load by Yearwise say FY 2000 to FY 2009 in Infopackage and load it to Write-optimised DSO (10 requests) and again load Request by request to Standard DSO and activate each request. I have selected the option in DTP's to  'Get All New Data Request by Request' and its working fine between WDSO and SDSO. But not working between Cube and SDSO. While Execute DTP its taking as a single request from SDSO to Cube.( 10 request to single request).
    Regards,
    Sari.

    Hi,
    How does your DTP setting looks like from below options ? It should be change log, assuming you are not deleting change log data.
    Delta Init. Extraction from...
    - Active Table (with archive)
    - Active Table (without archive)
    - Archive ( full extraction only)
    - Change Log
    Also if you want to enable deltas, please do not delete change log. That could create issue while further update from DSO.
    Hope that helps.
    Regards
    Mr Kapadia
    *Assigning points is the way to say thanks*

  • How do I store 4 hours of data and get it out of the "while loop" into a spreadshee​t file for documentin​g purposes? "See additional Text for additonal info"

    What a have is a VI that uses the following SUbvi's, starts with FP OpenVI, then FP Create TagVI, into a "While Loop" which contains a FP ReadVI outputting data into a Index ArrayVI outputting to a Display (DBL). This shows the output of a FP-AI-100 monitoring a 9v battery. I have to monitor this battery for a 4 hour period my problem is storing the 4 hours of data and getting it out of the "while loop" into a "Write to Spreadsheet File VI" all I seem to accomplish is just one data sample which I get into a spreed ship file with no problem. I just can't get 4 hours worth. By the way this is my first VI and I'm self
    trained so have mercy.

    I figured it out thanks.
    John Morris
    Glendinning Marine

  • How do I store 4 hours of data and get them out of the "while loop" into a spreadsheet file for documenting purposes? "See additional Text for additonal info"

    What a have is a VI that uses the following SUbvi's, starts with FP OPENvi, then FP Create Tagvi, into a "While Loop" which contains a FP READvi outputting data into a INDEX ARRAYvi outputting to a Display (DBL). This shows the output of a FP-AI-100 monitoring a 9v battery. I have to monitor this battery for a 4 hour period my problem is storing the 4 hours of data and getting it out of the "while loop" into a "Write to Spreadsheet File vi" all I seem to accomplish is just one data sample which I get into a spreed ship file with no problem. I just can't get 4 hours worth. By the way this is my first VI and I'm sel
    f trained so have mercy.

    I figured it out Thanks.
    John Morris
    Glendinning Marine

  • How can i get report between two dates?

    Hi
    how can i get report between two dates?
    for example i want get reports between 20/4/2002 & 27/4/2002.
    my table has date column and i can get first date( exam : .... where date:=a and/or ....i don't know this part)
    thanks alot.
    Regards
    The Oracle Reports Team
    http://otn.oracle.com/

    where exam_date between :from_date and :to_date
    from_date and to_date are user_parameter

  • How can I get extract the data between two cursors on an XY graph

    How can I get extract the data between two cursors on an XY graph

    Well, you say xy graph, so this might be a more complicated problem.
    For a waveform graph it's trivial. Simply get the two cursor indices (property: cursor index) and apply them to array subset of the data. Is that all you need?
    Here's how the above code would look like. using cursor.index instead of cursor.x elimnates the need to include scaling information.
    For an xy graph, there could be multiple segments (e.g. imagine a spiral that passes the desired x range multiple times from both sides). This would neeed significantly more code for a general solution.
    Message Edited by altenbach on 11-24-2009 07:53 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    cursorsubset.png ‏17 KB

  • How can get difference between 2 dates in the form of days

    how can get difference between 2 dates in the form of days

    Hi,
    Check the following program:
    REPORT ZDATEDIFF.
    DATA: EDAYS   LIKE VTBBEWE-ATAGE,
          EMONTHS LIKE VTBBEWE-ATAGE,
          EYEARS  LIKE VTBBEWE-ATAGE.
    PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,
                TODATE   LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.
    call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
      exporting
        i_date_from          = FROMDATE
        i_date_to            = TODATE
      I_FLG_SEPARATE       = ' '
      IMPORTING
        E_DAYS               = EDAYS
        E_MONTHS             = EMONTHS
        E_YEARS              = EYEARS.
    WRITE:/ 'Difference in Days   ', EDAYS.
    WRITE:/ 'Difference in Months ', EMONTHS.
    WRITE:/ 'Difference in Years  ', EYEARS.
    INITIALIZATION.
    FROMDATE = SY-DATUM - 60.
    Regards,
    Bhaskar

  • Finding difference of Hours between two dates

    I need logic to find the difference of number of hours between any two dates excluding saturdays & sundays. Please provide PLSQL code.

    my dear
    this is the pl/sql to create on db.
    &#0124; &#0124; This function it will created on the data if you like.
    &#0124; &#0124; the input parameter for this function is two date .
    &#0124; &#0124; you can add more feature on it because turn it felixable eg.
    &#0124; &#0124; you can execlude varaible days from paramteres....
    CREATE OR REPLACE FUNCTION GET_HOURS(P_FROM_DATE IN DATE ,
    P_TO_DATE IN DATE DEFAULT SYSDATE ,
    P_EXECLUDE IN VARCHAR2 DEFAULT '17' ) RETURN NUMBER IS
    V_CURR_DATE DATE := P_FROM_DATE ;
    V_ALL_DAYS NUMBER := 0 ;
    V_NET_HOURS NUMBER := 0 ;
    V_FROM_JUL NUMBER := TO_CHAR(P_FROM_DATE,'J');
    V_TO_JUL NUMBER := TO_CHAR(P_TO_DATE,'J');
    BEGIN
    FOR R IN V_FROM_JUL..V_TO_JUL LOOP
    IF INSTR(P_EXECLUDE,TO_CHAR(V_CURR_DATE,'D')) = 0 THEN
    V_ALL_DAYS := V_ALL_DAYS + 1 ;
    END IF;
    V_CURR_DATE := V_CURR_DATE+ 1 ;
    END LOOP;
    V_NET_HOURS := V_ALL_DAYS * 24 ;
    RETURN(V_NET_HOURS);
    END;
    -- this is for test senario
    SELECT GET_HOURS(SYSDATE-30) FROM DUAL ;
    SELECT GET_HOURS(SYSDATE-30,SYSDATE,'127') FROM DUAL;
    SELECT GET_HOURS(SYSDATE-30,SYSDATE,'0') FROM DUAL; -- to execlude zero days.

Maybe you are looking for

  • Import Basis Support Package 7.00 error

    Hi All, I wanted to apply Basis support package 9 for release 7.00 for our solution manager 4.0 system. When i started, it gave an error in the phase ADDON_CONFLICT? stage.. The message is as below: Phase ADDON_CONFLICTS_?: Explanation of Errors Conf

  • MSI K9A2GM - RealTek Randomly Installs After Reboot

    Someone here must've experienced this, I have an MSI K9A2GM and first let me say it's abit sad. The VGA slot feels very weak and like it would break right off if I pushed hard enough, it's only held on by some weird thin wires that connect to the PCB

  • Exchange Server 2010 and Iphone Version 4s or 5S, HTML Rendering on Iphone

    We have Exchange Server 2010 and using Iphone to receive and Send emails, When HTML based emails are opened from Iphone, The email just shows the text and not the HTML So the HTML is not rendered on IPhone, if the same email is FORWARDED from Outlook

  • Burned cd's won't work

    I burned two CD's on my roomate's computer (not the same video on both) with a couple of AVI movies that, while on my hard drive, worked just fine. I burned the CD and it mounted on my system fine, but VLC couldn't read it. It's not VLC's problem bec

  • No "Throwable" when  maximum path length of  NSS-Drive is exceeded!

    Hi, I have the problem that when I access a NSS-Drive (Novell Storage Services) via Windows (Java is running under Windows XP) that an exceeding path (bigger the 255 chars) produces no Throwable (Error or Exception whether checked or unchecked). At m