+ Reply to Thread
Results 1 to 5 of 5

Time from Text

  1. #1
    Registered User
    Join Date
    10-25-2003
    Posts
    20

    Question Time from Text

    We have a program at work that exports a text field from rotas as 1900-0700 or any variation of. I need to convert this into hours difference and also run across midnight. I've tried "=Right(A1,4)-Left(A1,4)", which gets me partially the way there, but not managed to progress beyond the very basics. I've played with the TIME function to no avail, i managed to achieve what i wanted over nine columns but that is ludicrous, any pointers, flashes of inspiration would be much appreciated. I'm prepared to put this into VBA later, but would rather have it as a calculation on the sheet
    Mole

  2. #2
    Forum Contributor
    Join Date
    06-23-2004
    Location
    Houston, TX
    Posts
    571
    Quote Originally Posted by Maurice
    We have a program at work that exports a text field from rotas as 1900-0700 or any variation of. I need to convert this into hours difference and also run across midnight. I've tried "=Right(A1,4)-Left(A1,4)", which gets me partially the way there, but not managed to progress beyond the very basics. I've played with the TIME function to no avail, i managed to achieve what i wanted over nine columns but that is ludicrous, any pointers, flashes of inspiration would be much appreciated. I'm prepared to put this into VBA later, but would rather have it as a calculation on the sheet
    ASSUMING that the data being exported is in Cell A1 and that it is always in this form "xxxx-yyyy", try this ...

    1. Format, say, cells B1 & C1 as hh:mm

    2. In Cell B1, enter this formula : =left(A1,2)&":"&mid(A1,3,2)

    3. In Cell C1, enter this formula : =mid(A1,6,2)&":"&right(A1,2)

    4. In Cell D1, enter this formula: =((C1-B1)+(B1>C1))*24

    There maybe a more elegant solution but this will work.
    BenjieLop
    Houston, TX

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Maurice,

    This formula will return the hours difference only.

    =ABS((VALUE(LEFT(A1, 4)) - VALUE(RIGHT(A1, 4)))/100)

    This will works as long as the format is 4 numbers either side of the hyphen.

    Sincerely,
    Leith Ross

  4. #4
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474
    Assuming that the format is consistent, try...

    =SUMPRODUCT(MID(A1,{1,3,6,8},2)/{24,1440,-24,-1440})

    Hope this helps!

  5. #5
    Registered User
    Join Date
    10-25-2003
    Posts
    20
    Thank you all,

+ 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