IF statement with Time

JTL9161

Well-known Member
Joined
Aug 29, 2012
Messages
567
Office Version
  1. 365
Platform
  1. Windows
We have a file that runs a few times everyday (m-f). For the ones that run in the afternoon depending on the size of each file it could end before 4:00pm or after. The file puts a end timestamp. After importing to Excel I use this formula to extract the time from the file. =MID('NORXFILE'!A18,SEARCH("ct",'NORXFILE'!A18),5)

So with this I might get a time like 7:06. I thought excel would not see this as a time since it was just imported but when I do =A44 - TIME(2, 0, 0) I get 5:06am then I use =A44+0.5 giving me 5:05pm in cell A45.

Now my question. Is there a IF statement that will look at this the imported time (7:06) and determine if it is before or after 4:00pm? If its before 4:00 I just want it to show as is. If the time is greater than 4:00 but less than 6:00 subtract 3 hours. If the time is greater than 6:00 then subtract 4 hours. Again I do not think excel is treating the data as time even though the cell is formatted to show like time. We need the time to be before 4:00 to stay in the same business day (even though 7:06 is in the same day)


Appreciate you help
James
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Excel treats the time 4pm as the value 16/24 = 0.6666.....

So, for example

=IF(A45>(16/24),"A","B")

will return "A" if the time in A45 is after 4pm, and "B" if the time in A45 is before 4pm.
You can replace "A" and/or "B" in the above example formula, with other formulas, such as
A45-(4/24)
if you want to subtract 4 hours.
 
Upvote 0
Try this

<table border="1" cellspacing="0" style="font-family:Calibri,Arial; font-size:11pt; background-color:#ffffff; "> <colgroup><col style="font-weight:bold; width:30px; " /><col style="width:100.75px;" /></colgroup><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td > </td><td >A</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >45</td><td style="text-align:right; ">03:06:00 a.m.</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >46</td><td > </td></tr></table><br /><table style="font-family:Arial; font-size:10pt; border-style: groove ;border-color:#00ff00;background-color:#fffcf9; color:#000000; "><tr><td ><b></b></td></tr><tr><td ><table border = "1" cellspacing="0" cellpadding="2" style="font-family:Arial; font-size:9pt;"><tr style="background-color:#cacaca; font-size:10pt;"><td >Cell</td><td >Formula</td></tr><tr><td >A45</td><td >=IF(TRIM(A44)+TIMEVALUE("00:00:00")>TIMEVALUE("06:00"),TRIM(A44)-TIMEVALUE("04:00:00"),IF(TRIM(A44)+TIMEVALUE("00:00:00")>TIMEVALUE("04:00"),TRIM(A44)-TIMEVALUE("03:00:00"),TRIM(A44)-TIMEVALUE("00:00:00")))</td></tr></table></td></tr></table>
 
Upvote 0
We have a file that runs a few times everyday (m-f). For the ones that run in the afternoon depending on the size of each file it could end before 4:00pm or after. The file puts a end timestamp. After importing to Excel I use this formula to extract the time from the file. =MID('NORXFILE'!A18,SEARCH("ct",'NORXFILE'!A18),5)

So with this I might get a time like 7:06. I thought excel would not see this as a time since it was just imported but when I do =A44 - TIME(2, 0, 0) I get 5:06am then I use =A44+0.5 giving me 5:05pm in cell A45.

Now my question. Is there a IF statement that will look at this the imported time (7:06) and determine if it is before or after 4:00pm? If its before 4:00 I just want it to show as is. If the time is greater than 4:00 but less than 6:00 subtract 3 hours. If the time is greater than 6:00 then subtract 4 hours. Again I do not think excel is treating the data as time even though the cell is formatted to show like time. We need the time to be before 4:00 to stay in the same business day (even though 7:06 is in the same day)


Appreciate you help
James

Does this work for you? I was assuming here your original time is in cell A44
=IF(AND(A44>=16/24,A44<=18/24),A44-3/24,IF(A44>18/24,A44-4/24,A44)) (Format the column this formula is in to Time
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

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