+ Reply to Thread
Results 1 to 9 of 9

Adding working hours

  1. #1
    Registered User
    Join Date
    07-11-2008
    Location
    Pune
    Posts
    28

    Adding working hours

    Hi All,

    I want to write a macro to add business hours to a datetime value, excluding weekends, non-working hours and holidays.

    e.g., I have a value (datetime) of "18/12/2009 11:30:00 AM", I want to add 10 hours to this, so as to get the result as "19/12/2009 12:30:00 PM".

    Please help.
    Last edited by sreerag446; 12-18-2009 at 07:37 AM. Reason: solved!

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Adding working hours

    Adding 10 hours will not give that time, it would be 21:30

    =+D8+((1/24)*10)
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    07-11-2008
    Location
    Pune
    Posts
    28

    Re: Adding working hours

    The answer in the example is by considering 8:00 to 17:00 as working hours.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Adding working hours

    Quote Originally Posted by sreerag446 View Post
    The answer in the example is by considering 8:00 to 17:00 as working hours.
    I can't see how you add 10 hours to come up with that time. The result you have is 25 hours ahead

  5. #5
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Adding working hours

    Hi,
    try this:

    with your date/time value in A2 and the business/working hours you want to add as a time value in B2

    =DATE(YEAR(A2),MONTH(A2),DAY(A2))+TIME(8,0,0)+(B2-(TIME(17,0,0)-MOD(A2,1)))

    make sure you enter the time value as hours in B2, i.e. 10:00

    hth

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Adding working hours

    I think it will prove a little more complex than that given the requirement to use working days only... (ie WORKDAY but with Time constraint)

    Personally, I'd recommend a search of WORKDAY and daddylonglegs... none of us will be able to match whatever he has created previously ... finding the appropriate formula might take a bit of searching though.

    http://www.excelforum.com/excel-gene...-to-dates.html

    EDIT: on that basis I suspect output for the given example should in fact be 21st rather than 19th ...
    Last edited by DonkeyOte; 12-18-2009 at 05:56 AM.

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Adding working hours

    This is daddylonglegs' formula:

    Please Login or Register  to view this content.
    where D2 is 08:00 and E2 is 17:00 ... A1 is start datetime and B1 is time to add... format result as date/time.

    Using your example the above would return 21/12/2009 12:30

    NOTES:
    -- Pre XL 2007 WORKDAY requires activation of Analysis ToolPak Add-In
    -- WORKDAY has optional parameter for public holiday range - see XL Help for more info.

  8. #8
    Registered User
    Join Date
    07-11-2008
    Location
    Pune
    Posts
    28

    Re: Adding working hours

    Thanks a lot everyone for replying...

    DonkeyOte, you soln is working excelent for me

  9. #9
    Registered User
    Join Date
    06-30-2011
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    1

    Post Re: Adding working hours

    Hi I wanted the formula to calcuate the difference in hh:mm:ss format between two cells with following conditions
    A1=11/Sep/2013 02:40:58 PM
    B1=18/Sep/2013 03:02:53 PM
    C1= HH:MM:SS format

    I need formaulas for calculatingfor the following conditions.
    1. Need to calculate the time difference for business hours Mon to Fri for business hours 09 to 19 excluding weekends.Means for 5 days a week
    2. Need to calculate the time difference between hh:mm:ss for 12 by 6
    3. Need to calculate the time difference for 24 hours.

    Thanks in advance.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1