+ Reply to Thread
Results 1 to 5 of 5

Date subtraction formula

Hybrid View

Kepa Date subtraction formula 05-20-2013, 04:48 PM
daddylonglegs Re: Date subtraction formula 05-20-2013, 04:56 PM
Kepa Re: Date subtraction formula 05-23-2013, 11:48 AM
arlu1201 Re: Date subtraction formula 05-23-2013, 12:49 PM
Kepa Re: Date subtraction formula 05-23-2013, 12:57 PM
  1. #1
    Registered User
    Join Date
    05-17-2013
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    3

    Date subtraction formula

    Aloha,

    If anyone would be so kind to help me with a formula I would be so grateful. I have the following formula:
    =(NETWORKDAYS(A1,B1)-1)*11/24+MOD(B1,1)-MOD(A1,1))

    I’m subtracting two dates while also subtracting out nights and weekends (11 operating hours).
    The formula works fantastic for some examples but not others:

    Cell A1 = 02/15/13 04:48 PM & Cell B1 = 02/15/13 04:48 PM C1 = 0:00:00
    But I get a negative number with the following example. The only difference is the dates, the times are the same.
    Cell A1 = 02/16/13 04:48 PM & B1 = 02/16/13 04:48 PM C1 = #####

    Or

    Cell A1 = 01/16/13 04:14 PM & Cell B1 = 01/17/13 10:21 AM C1 = 5:07:00
    But I get a negative number with the following example
    Cell A1 = 01/16/13 09:12 PM & B1 = 01/17/13 09:32 AM C1 = #####

    Mahalo,

    Kepa

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,697

    Re: Date subtraction formula

    Your formula should work OK for start and end times that are within working hours. The first negative number is caused because 16th February 2013 was a Saturday. In your last example 09:32 AM and 09:12 PM can't both be within an 11 hour working day. Assuming a working day 08:00 to 19:00 you can use this revised formula to work with start/end dates/times that may be outside working hours

    =(NETWORKDAYS(A1,B1)-1)*("19:00"-"8:00")+IF(NETWORKDAYS(B1,B1),MEDIAN(MOD(B1,1),"8:00","19:00"),"19:00")-MEDIAN(NETWORKDAYS(A1,A1)*MOD(A1,1),"8:00","19:00")
    Last edited by daddylonglegs; 05-20-2013 at 04:59 PM.
    Audere est facere

  3. #3
    Registered User
    Join Date
    05-17-2013
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    3

    Cool Re: Date subtraction formula

    Thank you so much daddylonglegs! I thought that was my problem but I would never have gotten there without you. This works beautifully.

    Mahalo nui loa,

    Kepa

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Date subtraction formula

    Based on your last post in this thread, its apparent that you are satisfied with the solution(s) you've received and have solved your question, but you haven't marked your thread as "SOLVED". I will do it for you this time.

    In future, to mark your thread as Solved, you can do the following -
    Select Thread Tools-> Mark thread as Solved.

    Incase your issue is not solved, you can undo it as follows -
    Select Thread Tools-> Mark thread as Unsolved.

    Also, since you are relatively new to the forum, i would like to inform you that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post which helped you. This adds to the reputation of the person who has taken the time to help you.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  5. #5
    Registered User
    Join Date
    05-17-2013
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Date subtraction formula

    Thank you arlu1201. I did look for the "mark as solved" but wasn't able to locate. I did however add to daddylonlegs reputation. As I was very appreciative of the quick accurate response but also for giving the explanation as to why my formula was incorrect.

    Thanks again.

    Kepa

+ 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