make a condition based on a time (not hours) - excel

I would like to make a condition to use IF formula when the cell A1 with a date in this format YYYY-MM-DD 20:30 has the time higher than 18:30 (date is not important and should not be taken in consideration).
For example 2000-01-22 20:30 follows under this condition and 2015-02-22 15:30 doesnt.
Any tip?
Thank you a lot.

You can rely on the underlying decimal representation of datetimes in Excel. Just check if the decimal part of your date is greater than [your time]/24.0 :
=if(MOD(A1,1) > 18.5/24, TRUE, FALSE)

How's this (if your data is in cell A1, place this in B1):
=IF(AND(HOUR(RIGHT(A1,5))>=18,MINUTE(RIGHT(A1,5))>=30),"After 6:30 PM","Before")
Note: This includes 18h30. To exclude it, just change the equation to simply >.

Related

Extract the hour from the h" hour(s) and "m" minute(s)" in excel

I have the list of data that showing the Hours and the Minutes that I extract from the system. I need to be extract the hours.
As example below, column B first row, the Hours would be 64 and the minutes would be 46.
But when I used the formula =Hour , its turn up the different value since its actually decimal number.
Cannot use left() , it will give the actual decimal number.
Updated:
We tried the #harun24HR 's but cannot readable the value.
But if you noticed, if i copy and paste the value is different. thats why the search not applicable.
4th Update:
To Solar Mike, I have tried the formula given from the thread the i think the value not readable
It's a time value which Excel stores as calculated value based on 24 hours = 1.
To retrieve the hours only you can use:
=INT(A2*24)
To retrieve the minutes only you can use:
=(A1-(INT(A1*24)/24))*24*60
Your time value is already a number in time format so you just need it to change it to decimal system. Dates and time values are numbers. Even if you see it as 30/09/2019 or 12:00:00, actually, for Excel, both cases are numbers.
First date Excel can recognize properly is 01/01/1900 which integer numeric value is 1. Number 2 would be 02/01/1900 and so on. Actually, today is 44659.
Now, about your data, you posted this screenshoot:
So the value is numeric, not text/string. In Excel, what you see is not always what you have. Probably that column has been formatted using custom mask. My fake data is like this:
The numeric value is 02/01/1900 16:46:36 (or 02/01/1900 4:46:36 PM it depends on your regional settings) but I've applied a custom format like this:
[hh]" hours" mm " minutes"
So what I have is a number but what I see is a text!
We have to work with the number (to be honest, ist's easier to work with numbers), so to extract the total hours, minutes and seconds.
Formula in B1: =INT(A1*24) total hours
Formula in C1: =INT(A1*24*60-B1*60) total minutes
Formula in D1: =A1*24*60*60-B1*60*60-C1*60 total seconds
This should guide you on whatever are you trying to achieve.
From your current sample data you try-
For hour =LEFT(A2,SEARCH(" ",A2)-1)
For minutes =RIGHT(SUBSTITUTE(A2," minutes",""),2)

Excel - Date Time Format ; If time is PM add a day

In excel I currently have data in date time format
For example: "11/10/2007 8:40:58 PM"
I am trying to extract the date and if the time is PM, I add a day.
if the time is AM, the date remains the same.
So since the time is 8:40:58 PM I would want 12/10/2007.
Is there a way in excel to do such a thing using formulas?
Please consider using the following formula. This uses the fact that in Excel in its date-time code uses 1 to represent a full day and fractions to represent the time. If timestamp is in A1 then:
=INT(A1)+IF((A1-INT(A1))>=0.5,1,0)
Regards.
This one works for me.
=IF(A1>0.5, A1+1, A1)
In order to have it only return the date right click on column B, select "Format" the take your pick.

Subtracting time gives "####" when it should be negative time

I have a simple case:
my j9-cell has formula: =h9-g9
when h9 has value 17:30 and g9 has value 17:00 j9 results 00:30 ... its ok!
but when h9 has value 16:30 it crashes..
Instead of showing -00:30 (as I expected) it shows a lot of #.
Am I missing something in formula? Thanks in advance.
Your calculation is producing a negative value, which constitutes an invalid date/time.
One way to fix it is to switch to the "1904 date system". To do this, select the "File" tab, then select "Options", then select "Advanced", then find the "Use 1904 date system" checkbox, and select it (this works when using Excel 2010 and newer).
Another way to fix it would be to change your formula to:
=IF(h9-g9<0, "-" & TEXT(ABS(h9-g9),"hh:mm"), h9-g9)
Warning: This produces a text value which may not be valid when used in other calculations.
What I would use:
=IF(H9>G9;"";"-")&TEXT(ABS(H9-G9);"h:mm")
This will generate the elapsed time as a text value, also if it's a negative result.
And since the result will always be a text, the format of the calculated field doesn't have to be changed to time.
Note: On a Dutch version of Excel the TEXT() formatting must be "u:mm" to make this work.
Excel does not appreciate negative time. You might want to incorporate a date into your calculations or possibly (maybe with a formula such as =IF(H9>G9,H9-G9,1+G9-H9) format 'negative' time results in red with conditional formatting, or use fractions of a day instead of time.
An addition to Mr. TL Couger's equation.
=IF(G8-E8<0,"-"&TEXT(ABS(G8-E8),"hh:mm"),TEXT((G8-E8),"hh:mm"))
Using this equation will always format a time difference(positive or negative) to a 00:00.

Excel - calculate date time

I am trying to calculate the hour difference between two times. What I've been doing now only gives me hour indications like 1:30, 2:45, etc but I can't make diagrams based on these values. If I get 2:30 as the hour difference, it should become 2,5. if the difference is 2:45 that should be 2,75.
Change your formula to:
(B2-A1)*24
and format as General
You should just be able to subtract 1 datetime from the other. Try this:
In cell A1, enter "09/17/2012 10:00" (Excel should automatically recognize this as a date)
In cell A2, enter "09/17/2012 11:30"
In cell A3, "=(A2-A1)*24". The result is 1.5.
The problem may be that you are trying to subtract 1 'time' from another 'time' without a date component. In that case, Excel may not recognize your value as a 'time'. Try adding a dummy date to the beginning of the time.
One limitation of this is that you will get an error response of "########" if the 2nd date is earlier than the 1st (because the result is negative). If this is an issue, try "=ABS(A2-A1)*24" instead.

Basic excel date and time problem

Have a list of dates in excel in the format (this comes originally from csv):
23/11/09 07:27:02
23/11/09 08:01:50
23/11/09 08:38:58
23/11/09 09:40:01
What I want to do is count the number of these falling between hour blocks, like 7-8, 8-9, 9-10 etc
Not sure how to get started, but one idea was just to put logic statements comparing the dates between these blocks, then adding the total "trues"
I can't get it to compare properly. When I type it the hour block marks,
e.g. 23/11/09 08:00
excel actually shows that as
23/11/2009 8:00:00 AM
and the compare doesn't work. Well actually it does the opposite of what it should.
that is:
=IF(C5>L1,IF(C5<M1,TRUE,FALSE),FALSE)
C5 being date in top codeblock, L1 and M1 being the hour blocks I manually entered in the second code block.
Has anyone got any ideas?
=hour(a1)=7
will return true if the time of the date/time value in cell A1 is between 7 and 8 (AM) and will otherwise return false.
Excel stores dates as number of days since 1900 or 1904 depending on your setting and the time as a fraction of the days. So 11:59 am 4th of July 1960 is held internally as '22101.4993055556'.
As such you cannot do plain charactrer string comparisons on dates. However ther ar lots of nifty time/date functions available to you.
You probably want :
=IF(HOUR(B1) > 8,IF(HOUR(B1)<12,"YES","NO"),"NO")
You should use Excel functions, like HOUR(), to extract the parts of the times, and apply the logic tests to those extracted values.

Resources