+ Reply to Thread
Results 1 to 8 of 8

Calculate difference between two dates and times in "days, hrs, mins

Hybrid View

  1. #1
    Registered User
    Join Date
    11-09-2013
    Location
    Delhi
    MS-Off Ver
    EXcel 2007
    Posts
    1

    Calculate difference between two dates and times in "days, hrs, mins

    Let say I have two cell with date and time together.

    Start date and time- A1: "01 Feb 2013 03:35:33"
    End date and time-B1:"05 Feb 2013 04:28:21"

    What should I do to calculate the difference between with the result "days","hrs","mins".

    If I calculate the difference B1 is greater than A1, then it should display as 4 days 7 hrs 28 mins

    If A1 is greater than B1 and it should be in negative, suppose
    Start date and time- A1: "05 Feb 2013 03:35:33"
    End date and time-B1:"01 Feb 2013 04:28:21"
    Result should be -4 days 7 hrs 28 mins

    Please help me.

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Calculate difference between two dates and times in "days, hrs, mins

    Are the cells containing the inputs text values or numbers formatted as dates?
    Do you want the seconds truncated or rounded?
    Last edited by Jakobshavn; 11-09-2013 at 09:48 AM.
    Gary's Student

  3. #3
    Forum Contributor amit.wilson's Avatar
    Join Date
    07-09-2013
    Location
    Gotham
    MS-Off Ver
    Excel for Mac 2011
    Posts
    283

    Re: Calculate difference between two dates and times in "days, hrs, mins

    Hi - try this in C1

    =IF(SIGN(B1-A1)=-1,"-","")&DAY(ABS(B1-A1))&" days "&HOUR(ABS(B1-A1))&" hrs "&MINUTE(ABS(B1-A1))&" mins"

    Cheers

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

    Re: Calculate difference between two dates and times in "days, hrs, mins

    Quote Originally Posted by amit.wilson View Post
    =IF(SIGN(B1-A1)=-1,"-","")&DAY(ABS(B1-A1))&" days "&HOUR(ABS(B1-A1))&" hrs "&MINUTE(ABS(B1-A1))&" mins"
    That's good amit.wilson........but if the difference in days is > 31 then you get incorrect results using DAY function, better to replace that with INT
    Audere est facere

  5. #5
    Forum Contributor amit.wilson's Avatar
    Join Date
    07-09-2013
    Location
    Gotham
    MS-Off Ver
    Excel for Mac 2011
    Posts
    283

    Re: Calculate difference between two dates and times in "days, hrs, mins

    Yes, you are right daddylonglegs. Thanks for catching that one.

    The correct formula is

    =IF(SIGN(B1-A1)=-1,"-","")&INT(ABS(B1-A1))&" days "&HOUR(ABS(B1-A1))&" hrs "&MINUTE(ABS(B1-A1))&" mins"

    Cheers

  6. #6
    Registered User
    Join Date
    01-08-2013
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Calculate difference between two dates and times in "days, hrs, mins

    This is almost exactly what I've been looking for. Is there any way to modify this formula for Net Workdays?

  7. #7
    Forum Contributor amit.wilson's Avatar
    Join Date
    07-09-2013
    Location
    Gotham
    MS-Off Ver
    Excel for Mac 2011
    Posts
    283

    Re: Calculate difference between two dates and times in "days, hrs, mins

    Q - got sucked into this and ended up with this very ugly formula:

    A1: 01/02/13 Fri 3:35 AM

    B1: 05/02/13 Tue 4:28 AM

    C1:
    Formula: copy to clipboard
    =MAX(0,(NETWORKDAYS((WORKDAY(A1,1*SIGN(B1-A1))),(WORKDAY(B1,-1*SIGN(B1-A1))))))+SUM((IF(WEEKDAY(A1,2)>5,0,(WORKDAY(A1,1*SIGN(B1-A1)))-A1))+(IF(WEEKDAY(B1,2)>5,0,B1-(WORKDAY(B1,-1*SIGN(B1-A1))))-INT( IF(WEEKDAY(B1,2)>5,0,B1-(WORKDAY(B1,-1*SIGN(B1-A1)))))))

    D1:
    Formula: copy to clipboard
    =TEXT(C1,"d:hh:mm:ss")


    Here's the logic (in case something more elegant is possible)

    - count full workdays between [start of next business day after A1] and [end of previous business day before B1]. These are full days. No hours, min or sec to be counted.

    - count front stub of hours,min,sec. From [start time A1] till [start of next business day after A1].

    - count end stub of hours,min,sec. From [end of previous business day before B1] till [end time B1].

    - Either or both stub are zero if either or both dates (A1, B1) are on a weekend, i.e. Sat, Sun. IF(WEEKDAY(A1,2)>5,0

    - Have put in the SIGN(B1-A1) formula to allow for negative calculations, i.e A1 date comes after B1.

    - As C1 is already so long and ugly, have used D1 to format the result.

    Cheers
    <-- If you're happy & you know it...click the star.:-)

  8. #8
    Registered User
    Join Date
    01-08-2013
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Calculate difference between two dates and times in "days, hrs, mins

    Thank you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. calculate difference between two dates and times in "days, hrs, mins, secs"
    By mankit87 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 09-03-2013, 04:27 AM
  2. Need to Calculate difference between 2 dates with times
    By KeithMark63 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-26-2012, 03:06 PM
  3. Replies: 2
    Last Post: 02-25-2006, 12:20 PM
  4. how do I calculate difference between two dates and times
    By PatCN in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-08-2005, 12:20 PM
  5. Calculate difference (mins) between 2 Times
    By Max in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 10-11-2005, 03:05 AM

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