WORKDAY() returns unexpected value on blank cells - excel

I am trying to set up conditional formatting to highlight when a date is in the weekend with this formula:
=WEEKDAY(A1,2)>5
This works fine when applied to a range only containing dates. However when there is any blanks or numeric values these also get formatted. I've tested and the formula =WEEKDAY(A1) where A1 is blank returns 6, implying it is a Saturday.
Question 1:
Does anyone know why this is?
Question 2:
How do I get around this, and leave blank cells unformatted? I've considered ISNUMBER and ISBLANK which would work for blanks, but not for numeric values within the range.

To detect the cell formatted as Date for limited number of date styles you can use CELL function:
=CELL("format",A1)
e.g. for date format m/d/yyyy it will return "D4" which can be used for testing the value being entered.
Please refer the answer provided by Foxfire and Burns and Burns for the other query.

A blank value equals to 0.
Dates in Excel work as numbers. First day Excel can recognize is number 1, which equals to 1st January 1900 (Sunday), number 2 means 2nd January 1900, and so on. Actually today is 25th september 2019, which numeric value is 43733.
So because 1 it's Sunday, 0 it's Saturday (it would be 0 JAnuary 1900, but that's not posible)
That explains the Does anyone know why this is?
About second question, because dates are also numeric values, you'll need to figure out how to check them. Maybe if the dates are in a specific range, you can check first if that number is between those values.
To see the numeric value of a date, just type any date in a cell, and change format to General or Numeric

Related

Why does the below date comparison in Excel return false?

The two columns in Excel contain custom date in a format of d-mmm. The date 19-Jul in column D11 is for the month 2021. The date 3-Jan in column H8 is for the month 2022. I am using the below formula to compare the two dates, and the result should be true, but somehow this formula returns false.
=IF(H$8>=$D11),"True","False")
One way to prove to yourself that the problem is likely the format of the "dates" themselves is to flip the formula: If =IF($D11>H$8,"True","False") (omitted first parenthesis as that seems to be an input error) also returns "False", then you are not comparing dates.
You can fix this issue a million different ways depending on what the cell is actually being stored as; I'm sure you will be able to quickly find something.

COUNTIFS statement, =COUNTIFS(V60:V91, ">="&0,V60:V91,"<="&30)

I'm attempting a COUNTIFS statement,
=COUNTIFS(V60:V91, ">="&0,V60:V91,"<="&30).
I believe I'm making syntactical error, but I can't finding it. Do you know what I'm doing wrong?
There is nothing wrong with your syntax. You have text-that-look-like-numbers in column V.
Note the right-alignment of the numbers in column V. These are true numbers and are counted by your formula in A1. Note the left-alignment of the text-that-look-like-numbers in column W. They are not counted by the same formula in B1.
Use Data, Text to Columns, Fixed Width, Finish on your column V to turn them into right-aligned true numbers.
Based on the comments in your question, you can try this if you are trying to count dates where the day of the month is Greater than or equal to zero (which would be all days), and the days that are less than or equal to 30...so all days except the 31st. If this is wrong interpretation, let us know. The following formula is based on your dates being stored as numbers and formatted to display as a date and not a date stored as text.
=sumproduct((day(V60:V91)>=1)*(day(V60:V91)<=30))

Issue with negative value when using NETWORKDAYS

I have created the formula
=-1+NETWORKDAYS(I18;J18;Helgdagar!A8:A35)
to calculate the difference between two dates. Standard Excel behaviour is that if it is the same date in both columns, it shows the value 1 but I want to display the value 0 instead (hence the -1+ in the beginning).
So far so good. The problem I have with this formula is if the date in J-column comes before the date in I-column. Let's say that it says April 8th in the J-column and April 10th in the I-column. Then it should say -2 but instead it says -3. How can I solve this?
=-1+IF(J18<I18,NETWORKDAYS(J18;I18;Helgdagar!A8:A35),NETWORKDAYS(I18;J18;Helgdagar!A8:A35))
Put an if statement in to compare which is the smaller value and then use the appropriate formula that works for you.
This is a way I have used:-
=NETWORKDAYS(I18;J18;Helgdagar!A8:A35)-sign(NETWORKDAYS(I18;J18;Helgdagar!A8:A35))
So it subtracts 1 if the NETWORKDAYS result is positive (including the case when both dates are the same) and adds one if it is negative.

Excel Formula: How to match a part of one cell to the part of another and remit the matched cell's value

I am trying to create a formula that will look in the range of date cells (C23:C28) and see if any of them contain the same month as the month listed in date cell B33. If so, I need it to remit the exact date listed in the matched cell (in column C). Any insight will help. Thanks!
Try this formula
=IFERROR(INDEX(C23:C28,MATCH(B33-DAY(B33)+1,INDEX(C23:C28-DAY(C23:C28)+1,0),0)),"No match")
The formula converts all dates (B33 and C23:C28) to the 1st of the relevant month and then makes the comparison - if any match (by year and month) you get the first of those matches (in order of placement in C23:C28). If there are no matches you get "No match"
You might be able to simplify if, say, all your dates will always be 1st of the month
Try:
=MIN(IF(MONTH(C23:C28)=B33,C23:C28))
To return the lowest date matching the month in B33.
Enter using [ctrl]+[shift]+[enter].
Using MAX does also require cse:
=MAX(IF(MONTH(C23:C28)=B33,C23:C28))
Or it will be in error without [ctrl]+[shift]+[enter].

Excel Calculate the date difference from today from a cell of "7/6/2012 10:26:42"

So I have a cell with 7/6/2012 10:26:42 inputted, I want to show the date difference from today in another cell.
I tried to extract 7/6/2012 with =LEFT(A1, Find(" ", A1, 1) -1) but turned out theres a value error.
The formula works when I make A1 '7/6/2012 10:26:42, however it is not ideal because I have to work with the whole column.
You can use the datedif function to find out difference in days.
=DATEDIF(A1,TODAY(),"d")
Quote from excel.datedif.com
The mysterious datedif function in Microsoft Excel
The Datedif function is used to calculate interval between two dates in days, months or years.
This function is available in all versions of Excel but is not documented. It is not even listed in the "Insert Function" dialog box.
Hence it must be typed manually in the formula box.
Syntax
DATEDIF( start_date, end_date, interval_unit )
start_date from date
end_date to date (must be after start_date)
interval_unit Unit to be used for output interval
Values for interval_unit
interval_unit Description
D Number of days
M Number of complete months
Y Number of complete years
YD Number of days excluding years
MD Number of days excluding months and years
YM Number of months excluding years
Errors
Error Description
#NUM! The end_date is later than (greater than) the start_date
or interval_unit has an invalid value.
#VALUE! end_date or start_date is invalid.
If that's a valid date/time entry then excel simply stores it as a number (days are integers and the time is the decimal part) so you can do a simple subtraction.
I'm not sure if 7/6 is 7th June or 6th July, assuming the latter then it's a future date so you can get the difference in days with
=INT(A1-TODAY())
Make sure you format result cell as general or number (not date)
For the difference between A1 and Today's date you could enter:
=ABS(TODAY()-A1)
which returns the (fractional) number of days between the dates.
You're likely getting a #VALUE! error in your formula because Excel treats dates as numbers.
DAYS(start_date,end_date):
For example:
DAYS(A1,TODAY())
Why don't you just make it easy and simple. If I need to know the number of days between today and say, March 10th, 2015, I can just enter the simple formula.
Lets say the static date is March 10th, 2015, and is in cell O5.
The formula to determine the number of days between today and O5 would be, =O5-Today()
Nothing fancy or DATEDIF stuff. Obviously, the cell where you type this formula in must have a data type of 'number'. Just type your date in normally in the reference cell, in this case O5.
=ROUND((TODAY()-A1)/365,0) will provide number of years between date in cell A1 and today's date
*In all instances the # refers to the cell number
You really don't need the datedif functions; for example:
I'm working on a spreadsheet that tracks benefit eligibility for employees.
I have their hire dates in the "A" column and in column B is =(TODAY()-A#)
And you just format the cell to display a general number instead of date.
It also works very easily the other way: I also converted that number into showing when the actual date is that they get their benefits instead of how many days are left, and that is simply
=(90-B#)+TODAY()
Just make sure you're formatting cells as general numbers or dates accordingly.
Hope this helps.

Resources