How to compare two dates in two cells in Excel? - excel

How do I compare two dates (if they're the same date) in two different cells in Excel?
e.g.:
Cell A1: 11/12/2018
Cell A2: 11/12/2018
If they match return "YES", otherwise "No".
=IF(NUMBERVALUE(A1)=NUMBERVALUE(A2),"YES","NO")
I tried the above but to no avail.

My guess is that the two dates have a time componant to them.
Try:
=IF(INT(A1)=INT(A2),"Yes","No")

Excel can easily get confused if A1 contains a genuine date or a date/time formatted as a date and A2 contains a text value.
First insert the following UDF in a standard module:
Public Function txet(r As Range) As String
txet = Application.WorksheetFunction.Trim(r.Text)
End Function
Then pick a cell and enter the formula:
=IF(txet(A1)=txet(A2),"YES","NO")

Related

How to count unique text values in a range, with some constraints given?

For example, I have a range cells:
Date Number
04/1/2019 A1
07/1/2019 A2
14/1/2019 -
15/1/2019 A1
02/2/2019 A3
07/2/2019 A1
and I want to count the amount of unique number in January, which is 2. What should I do? I am using anolder version of Excel, whcich does not support functions such as FILTER() and UNIQUE().
I have found a formula online:
{=SUM(IF(FREQUENCY(IF(data<>"", MATCH(data,data,0)),ROW(data)-ROW(data.firstcell)+1),1))}
which can count unique text values in a range which ignoring blank cells. However, I was unable to modify it to suit my usage, since it doesn't allow me to insert any criteria (such as date and ignore "-"). Most of the solution online involves functions such as FILTER() and UNIQUE(), which I am not able to use.
Slight modification of your attempt in D1, based on this handy website:
=SUM(--(FREQUENCY(IF((B2:B7<>"-")*(MONTH(A2:A7)=1),MATCH(B2:B7,B2:B7,0)),ROW(B2:B7)-ROW(B2)+1)>0))
Entered as array formula through CtrlShiftEnter
This boolean logic allows you to enter many more criteria if needed, such as YEAR if your dates can span more than the year 2019 and you need to filter on that too. Or include a check against empty values. It's very versatile.

Validating specific date format in Excel

I need to verify whether the dates in my Excel table are in the correct format, which is yyyy/mm/dd, so any other formats like mm/dd/yyyy would be incorrect.
I am using this formula:
=IF(NOT(ISERROR(DATEVALUE(TEXT(W2,"yyyy/mm/dd")))),"valid date","invalid date"
While the formula did pick up cells that did not contain a date, it failed to pick up cells that had dates in the wrong format like mm/dd/yyyy. What am I missing from my formula? Please help.
Thank you in advance.
Kev
If you want to check the format of a cell, put this User Defined Function in a standard module:
Public Function FormatChecker(r As Range) As String
FormatChecker = r(1).NumberFormat
End Function
With data in column A, in B1 enter:
=FormatChecker(A1)
and copy down. In C1 enter:
=IF(AND(LEFT(B1,4)="yyyy",MID(B1,6,2)="mm",RIGHT(B1,2)="dd"),"Good","Bad")
NOTE:
If you change the format of a column A cell, you will also need to refresh its contents to re-calculate column B. Use: F2 and Enter

Concatenate and preserve format in excel

I have Excel table when one cell has 'text' formating and literally is A1 ABC: and second cell is custom formatting and literally is B1 2013-11-4
I need in the third cell C1 to concatenate both and get ABC:2013-11-4
I tried this: =concatenate(A1,A2) but it resulted in ABC:41582
My question: how could I concatenate A1 and B1 in order to keep custom formating of B1 cell?
Thanks
You have to set the date format within the concatenation. The concatenation is retrieving the value behind the cell.
Instead, you can easily specify the date format using TEXT(cell, format):
=CONCATENATE(TEXT(A1,"YYYY-M-D"),A2)
The YYYY, M, and D represent four digit year (2013), month (11), and day (4) respectively.
The Answer provided by grovesNL fixed my problem.
Ticket could be closed.

Nested function in excel formula

I am trying to get the count of cells in a column containing dates having future date.
The column values are in string format.
I have figured out the formula as :
=COUNTIF(G19:G31,">" & TODAY())
This function works when the column values are in date format. But its failing if the cell format is in string format.
I have figured out the formula to convert a cell string value to date :
=DATEVALUE(G19)
Here are my queries:
1) How to apply DATEVALUE on a range , in this case from G19:G31?
2) How to combine these two formulas in to one single formula?
You could use:
=SUMPRODUCT(--((G19:G31+0)>TODAY()))
COUNTIF will not accept anything other than a range as its first argument so you can't use functions there.
An alternative is to write =SUM(IF(DATEVALUE(G19:G31) > TODAY(), 1, 0))
But this will be an array formula: you need to press Ctrl + Shift + Return once you've done editing, rather than just Return.

excel formula to combine 2 cells into 1 in specific format

I have 2 cells, one cell has just text A1 cell, text (hello) other cell B1 has a timestamp (3:55). I need to combine these cell to one with this format: hello#t=3m55s, or if timastamp is 1:12:11 format will be hello#t=1h12m11s. So cell A1 will change to this specific format base on B1 cell.
Thank you.
You could try this formula:
=A1&"#t="&IF(HOUR(B1)=0,"",HOUR(B1)&"h")&MINUTE(B1)&"m"&SECOND(B1)&"s"
The & concatenates each part together. However, if the timestamps are not correct for the mm:ss times, then it won't work.
EDIT: To deal with the issue of timestamps:
=A1&"#t="&IF(SECOND(B1)<>0,HOUR(B1)&"h"&MINUTE(B1)&"m"&SECOND(B1)&"s", HOUR(B1)&"m"&MINUTE(B1)&"s")
The issue with this is that it won't work for timestamps of the type "11:11:00" But I don't think there's much to be done, unless the string is first converted to text, which I could give some pointers on.

Resources