Consulting

Results 1 to 9 of 9

Thread: Hours Between dates & time

  1. #1
    VBAX Tutor CCkfm2000's Avatar
    Joined
    May 2005
    Posts
    209
    Location

    Hours Between dates & time

    hi all...

    i need to work out the hours between 2 dates and times, i've attached a sample copy for reference.

    please help

    thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    =DATEVALUE(SUBSTITUTE(C5,".","/"))-DATEVALUE(SUBSTITUTE(A5,".","/"))-1+(1-B5)+D5

    but it would be simpler if you used real dates.

  3. #3
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Very clever Bob, i have been fiddling with DateValue but as you pointed out the dates aren't in the correct format, i then tried a concatenation of the two adjacent cells to see if it would custom format as dd/mm/yyyy hh:mm:ss still no joy, i was scratching my head looking at if(and(or statements - well i had 30 mins to spare at work, a rareity these days!

    Regards,
    SImon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  4. #4
    VBAX Tutor CCkfm2000's Avatar
    Joined
    May 2005
    Posts
    209
    Location
    the dates are extracted from SAP.

    will look into it when i get back after the weekend now.

    thanks and have a good weekend.

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Simon Lloyd
    Very clever Bob, i have been fiddling with DateValue but as you pointed out the dates aren't in the correct format, i then tried a concatenation of the two adjacent cells to see if it would custom format as dd/mm/yyyy hh:mm:ss still no joy, i was scratching my head looking at if(and(or statements - well i had 30 mins to spare at work, a rareity these days!

    Regards,
    SImon
    Actually, we can do it without DATEVALUE

    =(SUBSTITUTE(C5,".","/"))-(SUBSTITUTE(A5,".","/"))-1+(1-B5)+D5

  6. #6
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    I see.....just like extra typing or am i missing the reason for using DATEVALUE? i tried both versions of course no change to the outcome, however the solution effectively deducts Time A from Time B but the result should have shown 24hrs 47mins 36Secs rather than 00:47:36, i tried formatting as [h]:mm:ss to see if that gave the true amount of hours but gave a long serial number!

    Regards,
    Simon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  7. #7
    Hi Simon,

    I was wondering about that result as well...then formatted it as:
    37:30:55 in the Time Category...

    Best,
    Wolfgang

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I used DATEVALUE to coerce the date string that was created out of the SUBSTITUTE. But, when you add or subtract from a date string, that does the coercing for you, obviating the need for DATEVALUE.

  9. #9
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Obviating is not a word a bear would use Bob.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

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