# Calculating total hours from a single cell that lists a timeframe

1. ## Calculating total hours from a single cell that lists a timeframe

Hi! I am stumped on this one, trying to figure out how to calculate total hours from a single cell that lists hours scheduled to work.
I know the simple solution is to split start time and end time into two different cells, however, that is not an option because I am trying to convert hours from an exported report that cannot be reconfigured at this time.

For example, I am looking for a formula that will return the total hours scheduled for C3:
C3 6:00A-2:00P

Any tips would be appreciated!

2. ## Re: Calculating total hours from a single cell that lists a timeframe

Hello Ashgemaehlich. Welcome to the forum.

Before embarking:
1. Are we to understand that the start/end times can span a Midnight?
2. And with that question in mind and this quote.
I know the simple solution is to split start time and end time into two different cells, however, that is not an option because I am trying to convert hours from an exported report that cannot be reconfigured at this time.
3. Does this rule out helper columns as well?

If so this may take a long complicated formula. It could be a while.

This is what I have so far. I am hopeful it can be shortened/simplified.
Formula:
`Please Login or Register  to view this content.`

 C D 3 6:00A-2:00P 8:00 4 11:00P-2:00A 3:00 5 7:00P-4:00A 9:00 6 11:00A-1:00A 14:00

3. ## Re: Calculating total hours from a single cell that lists a timeframe

Here is a shorter formula to try:

=MOD(SUMPRODUCT(TRIM(SUBSTITUTE(SUBSTITUTE(UPPER(MID(C3,CHOOSE({1,2},FIND("-",C3)+1,1),CHOOSE({1,2},99,FIND("-",C3)-1))),"P"," P"),"A"," A"))*{1,-1}),1)

4. ## Re: Calculating total hours from a single cell that lists a timeframe

In B2 then copied down
``Please Login or Register  to view this content.``

5. ## Re: Calculating total hours from a single cell that lists a timeframe

Or can try
=mod(lookup(9^9,right(left(substitute(substitute(c3,"a"," am"),"p"," pm"),len(c3)+3),{6,7,8})+0)-lookup(9^9,left(substitute(substitute(c3,"a"," am"),"p"," pm"),{6,7,8})+0),1)
``Please Login or Register  to view this content.``

6. ## Re: Calculating total hours from a single cell that lists a timeframe

Yet another!

=MOD(MMULT(0+TRIM(MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C7,"-",REPT(" ",2)),"A"," A"),"P"," P"),{1,9},8)),{-1;1}),1)

Regards

7. ## Re: Calculating total hours from a single cell that lists a timeframe

Here is another one:
Enter formula in D3 and copy down
Formula:
`Please Login or Register  to view this content.`

 v C D 3 6:00A-2:00P 8:00 4 11:00P-2:00A 3:00 5 7:00P-4:00A 9:00 6 11:00A-1:00A 14:00

8. ## Re: Calculating total hours from a single cell that lists a timeframe

Thank you for another lesson.

Root_, samba_ravi, XOR LX and AlKey.

MOD(sum,1)

Never occurred to me! (Groan!) That shortened my efforts a lot.

About the same as others above though not as short. Used REPLACE first.

=MOD(SUMPRODUCT((TRIM(MID(SUBSTITUTE(REPLACE(REPLACE(C3,LEN(C3),0," "),FIND("-",C3)-1,0," "),"-",REPT(" ",20)),{1,20},20)))*{-1,1}),1)

9. ## Re: Calculating total hours from a single cell that lists a timeframe

I can use helper cells if they are linked on a different sheet, I will be "exporting" a master data sheet and having all data pulled from there for calculations

##### Users Browsing this Thread

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

#### 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