Comparing two dates in excel returns a wrong result - excel-2016

I am comparing two dates and if the date 1 is greater than the date 2, the License status must be shown as "Valid license" if not the "Expired license" is shown.
but I always got "Expired license" in all case.
I am using this formula in Excel 2016:
IF([#[Date 1]]>=$BB$2;"Valid license";"Expired license")

The formula is correct.
'Date 1' column must be a date and also $bb$2
In Excel the date cells are numbers. You can check with =ISNUMBER(BB2) in any cell and the result must be TRUE. Also with 'Date 1'

I was comparing the dates in two columns to see if they were the same or different =IF(D2=N2,"same","different") and it was returning incorrect results.
The check suggested by Salvador Rodriguez Segura was the key to my problem. One column was not formatted as date, even though if I selected a cell and checked format, it showed as date. The =ISNUMBER function exposed the problem.
I selected the column and used Data/Text to Columns to correct the formatting. Then my simple formula worked.

Related

I need to convert total date to month only

I set up a google forms form for my work where my employees pass information and this information is recorded in a spreadsheet. The information, when recorded, automatically inserts a date and time in the first column of form responses. However, when I enter the code = month (a1), it always returns the answer "1" or "January" and this information does not match the date entered in the column. How do I fix this?
If you are entering '=month(a1)' for every row, then you are always taking the month of the top left cell in the sheet. You would need to adjust the row number for the row you are in.
You could use something like '=month(now())' to ensure you are always getting the month of the current date.

Get number of days between 2 dates of this format in Excel

I have 2 dates value in Excel. They are 20170124;202000 (24Jan2017 2020hrs 00secs) and 20170515;021146 (15May2017 0211hrs 46secs). I want to get the number of days between these 2 dates.
I tried to use the formula =DATEDIF(G838,G839,"md") where the first 2 parameters are cells containing the dates. The value returned was #VALUE!.
What Excel formula or VBA function can I use to get the number of days between the 2 dates?
Try this.......
=DATEDIF(DATE(LEFT(G838,4),MID(G838,5,2),MID(G838,7,2)),DATE(LEFT(G839,4),MID(G839,5,2),MID(G839,7,2)),"d")
If you have the string in cell A1, use the formula to convert it to an actual date before finding the difference,
=DATE(LEFT(A1,4),MID(A1,5,2),MID(A1,7,2))
You can include this directly in your formula too.

If particular cell is NOT BLANK copy down FORMULA from above cell

Basically I have the following formulas:
Column J: =IF(ISNA(VLOOKUP(I2,CCG,1,FALSE)),"Out of Area",VLOOKUP(I2,CCG,1,FALSE))
Column K: =INDEX(ResponsibleAgency,MATCH(N3,LeftLookup,0),MATCH(J3,TopLookup,0))
Column L: =IF(ISNA(VLOOKUP(N3,PPLookup,2,FALSE)),"Missing F Code",VLOOKUP(N3,PPLookup,2,FALSE))
Column M: =IF(ISNA(VLOOKUP(N3,PPLookup,3,FALSE))," ",VLOOKUP(N3,PPLookup,3,FALSE))
Basically, I only want these formulas to activiate provided that column A is populated with a date. If there is no date in column A, I want the cells to remain blank.
Is this possible?
Technically speaking, it is not possible to tell if cell contains a date or not in strict sense.
In Excel dates are in fact numbers representing number of days since January 1, 1900. I.e. today is 42066. It's the formatting that makes those numbers look like dates to user. If you pass a cell containing a date to any formula, it receives this number.
As a workaround, you can check if the cell satisfies two conditions:
It is a number.
It falls into some date range that makes sense.
For example, if your column contains goods delivery dates you usually don't expect them be previous century or 50 years into the future.
So you can wrap your formulae into something like this:
=IF(ISNUMBER(A1),IF(AND(A1>=DATE(2014,1,1),A1<=DATE(2015,12,13)),[LOGIC_IF_CORRECT_DATE_HERE],""),"")
Being said, it's still a workaround.

Excel, automatically updating variable in IF statement based on reference cell?

I have a sheet that needs to be updated monthly with a formula that needs to change with the month.
This is the formula: =IF($S3=AI$1,[#July],0)
The check is to make sure my values go into the correct category. After the category is determined correct, I need to take the month's values by referencing the month column in my table.
Question: Is there any way to make it so when I change the month somewhere, I can make the formula essentially move over a column to take the new month's values?
Note: I also have a similar case where instead of taking the month values verbatim, I'm summing the year's values til said month.
So I assume you have a table with column name January to December.
You can do this in at least two ways (I assume your month number is in cell A1)
Explicit: (in case these columns are not in order or adjacent to another)
=CHOOSE(A1,[#January],[#February], ... ,[#December])
Implicit: (if the months are next to each other:
=INDEX(TableName[#[January]:[December]],A1)
Obviously, I'd recommend the second option, if applicable.
If you want to sum from januar to the current month, you can use this little know trick/syntax:
=SUM([#January]:INDEX(TableName[#[January]:[December]],A1))

Find a previous date on a list closest to a specified date

I would like to have VBA code or formula that will take a variable date value and find it on a list range of dates. If it can't find the date I want it to find the closest previous date value. VLOOKUP works great for finding an exact match but I am struggling with the code to find the closest previous date.
My only thought is to create a loop where if it doesn't match it continues to subtract a day from the variable date until it can locate a match on the list. That does not seem like the best or most efficient method and I hope someone can recommend a simpler solution.
Example:
Variable Date = 01/26/2014
Date List
02/04/2014
01/27/2014
01/24/2014
01/13/2014
12/29/2013
Desired Result = 01/24/2014
Any help would be appreciated.
Suppose your list of dates was in cells A1:A5 and your check date was in cell C1, you could enter this function ENTERED AS AN ARRAY FORMULA:
=MAX(($A$1:$A$5<=C1)*A1:A5)
Rememeber, to enter it as an array formula, hit Ctrl + Shift + Enter when entering the formula.
Hope this does the trick!!
I went about this a little differently, no arrays needed
Find how many numbers are bigger then the one you are looking for with CountIf()
Then I used =Large this will find the nth dates in a list we have the nth we are looking for in the countIF()
=LARGE(A:A,COUNTIF(A:A,">="&TODAY()))
Vlookup can do this actually, if you set the final argument to true, which looks for an approximate match. You need your dates sorted from Oldest to newest and it will return the first date that is not after your search term.