Calculating Time that goes over 12 am

dkmusf

New Member
Joined
Sep 19, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Book1
ABCDEFGHIJKLMNOPQRSTUVWX
1ThursdayFridaySaturdaySundayMondayTuesdayWednesdayThursdayTotal ThursdayFridayTotal FridaySaturdayTotal SaturdaySundayTotal SundayMondayTuesdayWednesdayWeekly Total
203:30 pm - 02:00 am03:30 pm - 12:00 am10:00 am - 02:00 am10:30 am - 10:00 pmClosedClosed10:30 am - 10:00 pm03:30 am 02:00 am#VALUE!03:30 am 12:00 am#VALUE!10:00 am 02:00 am#VALUE!10:30 pm 10:00 pm#VALUE!ClosedClosed10:30 pm 10:00 pm#VALUE!
3
4
Sheet1
Cell Formulas
RangeFormula
H2H2=REPLACE(A$2,7,10,"")
I2I2=REPLACE(A$2,1,10,"")
J2,S2,P2,M2J2=IF(I2="","",I2-H2)
K2K2=REPLACE(B$2,7,10,"")
L2L2=REPLACE(B$2,1,10,"")
N2N2=REPLACE(C$2,7,10,"")
O2O2=REPLACE(C$2,1,10,"")
Q2Q2=REPLACE(D$2,7,10,"")
R2R2=REPLACE(D$2,1,10,"")
V2V2=REPLACE(G$2,7,10,"")
W2W2=REPLACE(G$2,1,10,"")
X2X2=J2+M2+P2+S2
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
You could use VBA to get a custom function:

VBA Code:
Public Function getTimeDiff(a As Date, e As Date) As Date
    'getTimeDiff= 24 * (TimeValue(e) - TimeValue(a))
    Dim tBeg#, tEnd#
    tBeg = TimeValue(a)
    tEnd = TimeValue(e)
    If tEnd < tBeg Then tEnd = tEnd + 1
    getTimeDiff = 24 * (tEnd - tBeg)
End Function

Book1.xlsm
ABC
1startendhours
210:00:00 PM6:00:00 AM8.00
Sheet33
Cell Formulas
RangeFormula
C2C2= getTimeDiff(A2,B2)
 
Upvote 0
My approach to this may be different from many others. But, I always try to use a date and time value and format only the time portion.
mr excel questions 20.xlsm
ABC
1Difference
22023-02-24 22:152023-02-25 02:3004:15
344981.9270844982.104170.177083333
422:1502:3004:15
Sheet2
Cell Formulas
RangeFormula
C2:C4C2=B2-A2
A3:B4A3=A2
 
Upvote 0
try
T202303a.xlsm
ABCDEFGHIJ
1ThursdayFridaySaturdaySundayMondayTuesdayWednesdayThursdayTotal Thursday
203:30 pm - 02:00 am03:30 pm - 12:00 am10:00 am - 02:00 am10:30 am - 10:00 pmClosedClosed10:30 am - 10:00 pm3:30 PM2:00 AM10:30
3
5f
Cell Formulas
RangeFormula
H2H2=--TEXTBEFORE(A2,"-")
I2I2=--TEXTAFTER(A2,"- ")
J2J2=IF(I2="","",I2-H2+(H2>I2))
 
Upvote 0
If you don't like VBA use this:

Book1.xlsm
ABC
1startendhours
210:00:00 PM6:00:00 AM8.00
310:00:00 PM6:00:00 AM8.00
Sheet33
Cell Formulas
RangeFormula
C2C2= getTimeDiff(A2,B2)
C3C3= IF(B3<A3,24*(B3+1-A3),24*(B3-A3))
 
Upvote 0
Another option is the MOD function:
Book1
ABCD
1ThursdayThursdayTotal Thursday
203:30 pm - 02:00 am3:30 PM2:00 AM10:30
31:00 PM5:45 PM4:45
Sheet2
Cell Formulas
RangeFormula
B2B2=--TEXTBEFORE(A2,"-")
C2C2=--TEXTAFTER(A2,"- ")
D2:D3D2=IF(C2="","",MOD(C2-B2,1))
 
Upvote 0
T202303a.xlsm
ABCDEF
6ThursdayFridaySaturdayThursdayFridaySaturday
703:30 pm - 02:00 am03:30 pm - 12:00 am10:00 am - 02:00 am10:308:3016:00
803:30 pm - 02:00 am03:30 pm - 12:00 am10:00 am - 02:00 am10.58.516
9
5f
Cell Formulas
RangeFormula
D7:F7D7=IF(A7="","",TEXTAFTER(A7,"- ")-TEXTBEFORE(A7,"-")+(TEXTBEFORE(A7,"- ")>TEXTAFTER(A7,"-")))
D8:F8D8=IF(A8="","",TEXTAFTER(A8,"- ")-TEXTBEFORE(A8,"-")+(TEXTBEFORE(A8,"- ")>TEXTAFTER(A8,"-")))*24
 
Upvote 0
T202303a.xlsm
ABCDEFG
6ThursdayFridaySaturdayThursdayFridaySaturday
703:30 pm - 02:00 am03:30 pm - 12:00 am10:00 am - 02:00 am10:308:3016:00or
803:30 pm - 02:00 am03:30 pm - 12:00 am10:00 am - 02:00 am10.58.516
5f
Cell Formulas
RangeFormula
D7:F7D7=LET(s,TEXTBEFORE(A7,"-"),e,TEXTAFTER(A7,"- "),e-s+(s+0>e+0))
D8:F8D8=LET(s,TEXTBEFORE(A8,"-"),e,TEXTAFTER(A8,"- "),e-s+(s+0>e+0))*24
 
Upvote 0
Thank you, everyone. I will need to unpack all of this later this evening!!!
 
Upvote 0
T202303a.xlsm
ABCDEF
903:30 pm - 02:00 am03:30 pm - 12:00 am10:00 am - 02:00 am10.58.516
10
5f
Cell Formulas
RangeFormula
D9:F9D9=LET(s,TEXTBEFORE(A9,"-"),e,TEXTAFTER(A9,"- "),MOD(e-s,1)*24)
 
Upvote 0

Forum statistics

Threads
1,215,461
Messages
6,124,955
Members
449,199
Latest member
Riley Johnson

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top