Calculate elapsed Workhours between 2 timestamps

Hi,
Is there any function that would return the number of workhours between 2 timestamps in the tool depending upon the calendar defined. It would be great if someone could provide any inputs of the way to calculate this.
Thanks,
Sree

There would be a bit of code involved but here's one approach to calculating the number of working hours based on calendar rules.
There's an OOTB method that returns the number of days between to times based on a specific Calendar rule:
calendar as Fuego.Lib.CalendarRule
workDays as Int
calendar = CalendarRule.fetch(calendarName : "US_STD")
elapsedDays calendar
    using fromDate = 'now',
          toDate = futureDate
    returning workDays = workDaysIf you have to have the number of hours, you'd first have to find out how many working days are left in today:
totalHours as Int - 0
todayStartLaborTime as Time
todayEndLaborTime as Time
closeTime(CalendarRule, time : 'now', out endLaborTime : todayEndLaborTime)
startTime(CalendarRule, time : 'now', out startLaborTime : todayStartLaborTime)
// are we already in the workday?
if todayStartLaborTime < 'now' && todayEndLaborTime > 'now' then
    // get the number of work hours left today
    timedifference = todayEndLaborTime - 'now'
    totalHours = totalHours + timedifference.hours
// workday not started today?
elseif todayStartLaborTime > 'now' then
    timedifference = todayEndLaborTime - todayStartLaborTime
    totalHours = totalHours + timedifference.hours
endThen you would need to see how many hours are in the final working day:
futureStartLaborTime as Time
futureStartLaborTime as Time
futureEndLaborTime as Time
startTime(CalendarRule, time : futureDate, out startLaborTime : futureStartLaborTime)
closeTime(CalendarRule, time : futureDate, out endLaborTime : futureEndLaborTime)
// how many hours in the last workday are there?
if futureDate > futureStartLaborTime && futureDate < futureEndLaborTime then 
    // get the number of work hours left that day
    timedifference = futureStartLaborTime - futureDate
    totalHours = totalHours + timedifference.hours 
end Finally, you'd want to loop through the days between the start and end days (non-inclusively) and get the number of working hours in each day.
nextStartTime as Time
nextEndTime as Time
previousDayEndTime as Time = 'now'
while previousDayEndTime < futureDate do
    // get the next day's start and end times
    nextWorkDayStartTime calendar
        using time = previousDayEndTime
        returning nextStartTime = nextStartTime
    nextWorkDayCloseTime calendar
        using time = previousDayEndTime
        returning nextEndTime = nextCloseTime
    timedifference = nextEndTime - nextStartTime
    totalHours = totalHours + timedifference.hours
    previousDayEndTime = nextEndTime
endHope this helps,
Dan

Similar Messages

  • 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

  • Time calculation: type date or timestamp; how to calculate time in between?

    Dear experts,
    I like to create a simple flightbook table: FLIGHTID, TAKEOFFTIME, LANDINGTIME.
    1. First question:
    I prefer to use UTC as timezone in the app.
    Which datatype would be best to take?
    date or timestamp?
    2. Secound question:
    I like to calculate the flighttime between TAKEOFFTIME, LANDINGTIME?
    How do I do this best?
    Add a column flighttime?
    How do I calculate the flighttime between TAKEOFFTIME, LANDINGTIME?
    Advice and tips are very welcome!
    Kind regards
    Lorenz
    --

    Hi, Lorenz,
    lokeller wrote:
    Dear experts,
    I like to create a simple flightbook table: FLIGHTID, TAKEOFFTIME, LANDINGTIME.
    1. First question:
    I prefer to use UTC as timezone in the app.
    Which datatype would be best to take?
    date or timestamp?Based on what you've said, I'd use DATE. DATEs are much more conveinet to manipulate than TIMESTAMPs.
    TIMESTAMPs are good if you need fractipons of a second. For airplane flights, you probably don't even need seconds, let alone fractions.
    TIMESTAMP WITH TIME ZONE is useful for multiple time zones. You're converting everything to UTC, so you don't need that.
    2. Secound question:
    I like to calculate the flighttime between TAKEOFFTIME, LANDINGTIME?
    How do I do this best?
    Add a column flighttime?No. Only consider adding a column if you're frequently filtering on flight time and need to index it. It's very rare when you need to do this. Normally, you just store the takeofftime and landingtime, and compute the flightime from these when you need to.
    How do I calculate the flighttime between TAKEOFFTIME, LANDINGTIME?
    landingtime - takeofftimeproduces a NUMBER, the number of days that landingtime is after takeofftime. You'll probably want the time in units of 1 hour or 1 mintue, not 1 day, so multiply that difference by the number of hours (as shown below) or minutes in a day:
    SELECT     flightid
    ,     takeofftime
    ,     landingtime
    ,     (landingtime - takeofftime) * 24     AS hours_in_flight
    FROM     flightbook
    ;

  • When using historical datalogging, is it possible to hide the elapsed time between tag updates when viewing on a graph?

    When my process stops, I am reading an array of tags(datapoints) and writing the max and average to memory tags for data logging. However, when viewing the data, the elapsed time between cycles spreads the data out unevenly. It could be 90 seconds between cycles or maybe two hours or longer. Is there a way to convert the time axis data to be just consecutive datapoints?? It would be like logging data based on a particular condition happening rather than time-based trending. Should I try to use the data set logger examples instead?? I would prefer to use the built-in datalogging features rather than writing to databases.

    You could export your data to a spreadsheet file and then actually write then again in a second database using this example program in the devzone
    http://zone.ni.com/devzone/conceptd.nsf/webmain/5A921A403438390F86256B9700809A53?opendocument
    Using this program (if you don't want to modify it, which would take a reasonable amount of time specially if you are not familiar with VI-Based Server) You would have to generate a collum in your spreadsheet file to be the timestamp, it would be a artificial timestamp.
    What you could do in your application is to first save the data to file and then read from file, substitute the collum timestamp for the "artificial one" and then write it to the database, again, with that you would not need to modify this program.
    However if you have the time and is willing to work with VI-based server you could try to modify the example program to be adapted for your purposes.
    I hope it helps
    Good Luck
    Andre Oliveira
    Applications Engineer
    National Instruments

  • Calculate the Difference Between two dates excluding weekends and Holidays

    Hi,
    We need to calculate the difference between the two dates by excluding the Local public holidays (It is global and varies across countries) and weekends should not be included in calculation for a business day in OBIEE.
    We have two dates: Open date and close date when ever close date is null we are calculating age based on taking the current timestamp and need to exclude the weekends and Holidays when ever the close date is null.
    Ex:
    Col1 col2 Total
    11/9/2010 2:46:38 PM Null 13
    11/2/2010 8:06:26 PM 11/3/2010 5:37:03 PM 1
    (In the Total we shouldn't include the weekends,holidays)
    Please let me know how to calculate the difference between two dates by excluding the weekends and holidays.
    Thanks
    Edited by: user10441472 on Nov 22, 2010 3:14 PM

    You already asked this question and I answered it...
    Re: calculation of Business day in OBIEE

  • How to find the elapsed time between 2 events ?

    I want to use the robot class and I have register all events in a file but when I use the Robot. It isn't synchronous. So I should find th elapsed time between two events for reproducing them with the method delay of the class Robot.
    Thanks

    It sounds like you want to reproduce the events with varying time between the events? This is a good idea for a couple of reasons 1) it's possible to enqueue events so quickly that Robot gets ahead of the Java GUI, and 2) every human does their mouse/keyboard activity at varying (and relatively slow, relative to the computer that is) rates of speed. It would help make a more realistic interaction to vary the speed of event reproduction.
    Since you can't control the amount of time between the call to Robot and when the event arrives in the application, you can't be ultimately precise about this. You'll have to accept a teensy bit of slop in the process and just live with it.
    That is ... you can do something like robot.method1() .. Thread.sleep(1) .. robot.method2() .. Thread.sleep(1) ... and that will give slight delays. If you vary the value for Thread.sleep you can vary the event reproduction speed. Early in the development of Robot I experimented with something like this - I set up an EventQueue listener to capture all mouse/keyboard events (remember that each comes with a timestamp) and then reproduced events using the time intervals from the captured events to control the Thread.sleep times between Robot calls. It worked pretty well, and the mouse would dance around in the same way I moved the mouse around.
    - David

  • How can I calculate the delta between 2 cursors on an xy graph

    I have an xy graph with two sets of cursors: cursor0 and cursor1. I want to calculate the delta between cursor0 y position and cursor1 y position. I have created a cursor y position property node that gives me the y position of cursor1, but how do I get the y position for cursor0? There does does not seem to be any mechanism for selecting which cursor the property node references.
    Thanks
    John

    There is a more rapid solution : you can read all the cursors attributes in a single property node call, then extract the info you need, as shown in the attached picture.
    Message Edité par chilly charly le 08-29-2005 09:24 PM
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Example_BD.png ‏2 KB

  • MDX - how to calculate the sales between a certain period and the currentmember with a max date

    Hi all,
    1)I need to calculate the sales between W1 and the currentmember, but the max date should be W20. How can I solve this in MDX?
    MEMBER [Measures].[Q1 act.period to date sales] AS
    Sum(
    [Date invoice].[Bonus calendar - Week].[Bonus week of year].&[2015]&[1]
    [Date invoice].[Bonus calendar - Week].Currentmember
    *[CurrentSalesPeriod]
    ,[Measures].[Sales amount]
    This is the measure I have, I need to add the max date is W20. 
    2)Also, when I calculate the sales between [Date invoice].[Bonus calendar - Week].[Bonus week of year].&[2015]&[40] and the currentmember, for example being [Date invoice].[Bonus calendar - Week].[Bonus week of year].&[2015]&[20],
    he calculated the sales between this period. However, in theory this is not possible because W20 < 40. Is there any way I can put a constraint on this that he only calculates the sales if the currentmember is > the start period?
    Thanks in advance!

    Y, you can put a check on to determine if currentmember > start period.
    Firstly, your period keys are composite of year and period (indicated by the two ampersands in the fully qualified date above). If your period keys were non-composite (eg 201501) it would be a simple matter of 
    IIF([Date invoice].[Bonus calendar - Week].Currentmember.properties("key") > [Date
    invoice].[Bonus calendar - Week].[Bonus week of year].&[2015]&[1].properties("key"),[Measures].[Sales
    amount],null)
    There are advantages of having two period attributes on the dimension, one with a fully unique
    key and the other with just the period of fy, but that's digressing.
    With your composite keys, you could use a calc like the following for the SUM()
    Sum(
    [Date invoice].[Bonus calendar - Week].[Bonus week of year].&[2015]&[1]
    [Date invoice].[Bonus calendar - Week].Currentmember
    *[CurrentSalesPeriod]
    ,IIF([Date
    invoice].[Bonus calendar - Week].Currentmember.parent.properties("key") +[Date
    invoice].[Bonus calendar - Week].Currentmember.properties("key") > [Date
    invoice].[Bonus calendar - Week].[Bonus week of year].&[2015]&[1].parent.properties("key")+[Date
    invoice].[Bonus calendar - Week].[Bonus week of year].&[2015]&[1].properties("key"),[Measures].[Sales
    amount],null))
    Richard

  • 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.

  • How to read time stamps from a spreadshee​t and calculate the difference between consecutiv​e time stamps?

    Hi,
    I am new to Labview. This question might be a joke to some of you here, but any help would be greatly appreciated. I have a spreadsheet with time stamps and power outputs from a generator. I am supposed to calculate the difference between consecutive time stamps, which will act as a delay for the next power output update that needs to be sent. For example, lets say that I have to following data:
    Time Stamp                    Power Output
    11:00:00 AM                       3kW
    11:00:02 AM                       2.9kW
    11:00:04 AM                       3.2kW
    11:00:06 AM                       3.1kW
    The above data doesn't make any sense, but it is just for the purpose of this question.
    So, I have to read 11:00:00 AM and 3kW initially - 3kW is the initial request that

    Hello
    you can simple subtract one time from the other one and so you get the difference. -> Example
    Mike
    Attachments:
    Unbenannt 2.vi ‏8 KB

  • How to read time stamps from a spreadsheet and calculate the difference between consecutive time stamps?

    Hi,
    I am new to Labview. This question might be a joke to some of you here, but any help would be greatly appreciated. I have a spreadsheet with time stamps and power outputs from a generator. I am supposed to calculate the difference between consecutive time stamps, which will act as a delay for the next power output update that needs to be sent. For example, lets say that I have to following data:
    Time Stamp                    Power Output
    11:00:00 AM                       3kW
    11:00:02 AM                       2.9kW
    11:00:04 AM                       3.2kW
    11:00:06 AM                       3.1kW
    The above data doesn't make any sense, but it is just for the purpose of this question.
    So, I have to read 11:00:00 AM and 3kW initially - 3kW is the initial request that is sent. Then I have to

    Repeated forum post
    Please view http://forums.ni.com/ni/board/message?board.id=170&message.id=294435
    Regards,
    Juan Galindo
    Applications Engineer
    National Instruments

  • Calculate the variance between quarters and store it in a scenario

    Hi,
    Can anyone suggets how I can write a rule to calculate the variances between quarters, Qtr1 vs Qtr2, Qtr2 vs Qtr3 etc, and store them in a scenario so that I dont calculatethem on a report ?
    Thanks,
    IK

    Hi. Why don't you want to do this on the report - it's much easier and you can get favorable/unfavorable comparisons? But, if you want to do the rule, here's the approach.
    Create the scenario with QTD as the frequency so you don't have monthly periods
    Limit the rule to run just for the scenario and don't run any other rules for the scenario
    Use a select case to determine which period (Q1, etc.) is being calc'd to populate variables that contain the source period and year (for going back a year to Q4).
    Write the rule to compare data from current quarter in the real scenario to the prior quarter in the real scenario. Something like HS.Exp "A#ALL = A#ALL.S#Actual.P#Jun.W#QTD - A#ALL.S#Actual.P#Mar.W#QTD. But, you may want to adjust this to calculate a favorable/unfavorable variance on the revenue/expense accounts, so you'd need to loop through the accounts and look at the account type.
    You'd want to rerun the rule at all value members for both base entities and parent entities. May need to clear all existing data (HS.Clear "A#ALL") in the scenario/year/period/entity/value first.
    Do a consolidate all on the scenario to pull the data across and do the math
    Have fun, but you really should still with doing the comparison in the reports.
    Eric

  • Sql to get average timestamp between 2 timestamps

    I know similar question has been asked many times in several forums. Most of them dealt with fetching interval or difference between timestamps in numbers (hours, mins,...) or using PL/SQL or custom functions.
    Without using PL or custom functions, but just a sql what's the most efficient way of calculating timestamp that's half way between 2 timestamps?
    alter session set nls_date_format = 'YYYY-MM-DD HH24:MI:SS';
    select
    to_date('2013-12-05 04:30:20','YYYY-MM-DD HH24:MI:SS') start_date,
    to_date('2013-12-06 15:00:30','YYYY-MM-DD HH24:MI:SS') end_date,
    '' avg_date
    from dual;
    Thanks,
    -srinivas y.

    Hi,
    Here's one way to get the mid-point between 2 DATEs:
    WITH  input_data  AS
        SELECT  TO_DATE ('2013-12-05 04:30:20', 'YYYY-MM-DD HH24:MI:SS')   AS start_date
        ,       TO_DATE ('2013-12-06 15:00:30', 'YYYY-MM-DD HH24:MI:SS')   AS end_date
        FROM     dual
    SELECT  start_date, end_date
    ,       start_date + ( (end_date - start_date)
                         / 2
                         )    AS mid_point
    FROM    input_data
    If start_date and end_date are already in a table, then use that table instead of a sub-query like input_data above.
    Message was edited by: Frank Kulash
    Actually, this works equally well if start_date and end_date are TIMESTAMPs.
    (TIMESTAMP is a separtate datatype from DATE.  You asked about TIMESTAMPs, but the example you gave used DATEs.  If you really want TIMESTAMPs, you can use TO_TIMESTAMP instead of TO_DATE.)

  • Calculate the difference between date on essbase

    Hi Everbody,
    I want to calculate the difference between 2 date in essbase 9.3. Is any one did this practice ?
    I have done this but that is not a better way. so please share your thought with me.
    Regards
    Vikram Singh

    Hi Vikram,
    Take a look at a post I did a while back at:
    Re: Calculations with dates
    Let me know if that answers your question or you have specific questions once you review that.
    Regards,
    John
    http://www.metavero.com

  • Calculate the difference between Creation date and key date

    Hello
    I want to calculate the difference between creation date of the document with key date(todays date). How can i do that in the query designer. Also then I want to restrict my key figure on this difference if it is =10..please can someone suggest what can be done
    thanks

    Hi Grame...
    For the days calculation ..
    I suggest you to use replacement path ..
    I have the reference that you can see the sample. The case of samples is also about day calculation.
    http://www.sd-solutions.com/documents/SDS_BW_Replacement%20Path%20Variables.html
    Hopefully it can help you a lot.
    Regards,
    Niel.

Maybe you are looking for

  • Creating and Saving My Own Midi Loops/Instrument

    I know how to create a new instrument in GB but can I also create and save midi loops that are attached to the instrument and save them in the loop browser? The same way other midi parts work so when you drag the midi out of the loop browser and into

  • CRM 2007 : Unable to access the BP_HEAD component

    Hello, I'm a basis guy, very new to SAP CRM. We have been asked to install CRM 2007. We are able to ping the crm server from transaction sicf. The users are able to access the webclient, they're able to acess the component "CRM_UI_FRAME" Therefore, i

  • I want to upgrade my macbook pro's ram from 4 to 6 or 8gb. mine is mid 2010 macbook pro..

    i want to upgrade my macbook pro's ram from 4 to 6 or 8gb. mine is mid 2010 macbook pro.. Configuration 2.4GHz Intel Core 2 Duo 4GB 1066MHz DDR3 SDRAM - 2x2GB 250GB Serial ATA Drive @ 5400 rpm i am looking at http://www.flipkart.com/transcend-ddr3-4-

  • Changes in the sales order

    Hi, What are the tables where i can see the changes made for a position in a sales order. I want to make a program/query to see when a user change the material code for a position in a sales orders. Thankyou.

  • How to put the SQL-statement returned value into the field (as a default)

    Hi, I am using Developer/2000 (Forms Designer) under windows 98. Please tell me how to put the SQL-statement value (as a default value) into the field before enter-query mode. Noted that I have tried the following ways but still some problems:- 1) Pl