Validating specific date format in Excel - excel-formula

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

Related

How to compare two dates in two cells in 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")

Using MONTH() in a cell formula converts the cell type to "Custom" date format

I have a cell that has the formula =INDIRECT(CHAR(COLUMN()+65)&ROW())*MONTH($A$1)/12 where INDIRECT references an integer and $A$1 is a date. For some reason, the MONTH part converts the entire cell into a date instead of a number. How do I change the formula to have it return a number in number format? (Manually changing each cell through the ribbon is not an option for me).
I haven't tested this (and I can't comment till I get 50 rep), but you could wrap the whole thing in a text formula, then multiply by 1:
=TEXT(INDIRECT(CHAR(COLUMN()+65)&ROW())*MONTH($A$1)/12,"#")*1
Hope this helps!

Excel Date formatting replace "." with "/"

I have entered the date in the excel as 19.04.2015 but now I want the "." in these dates to be replaced with "/", so that the output should be 19/04/2015
Does anyone know the formula for this?
Tutorial to change the date format. The way you should do it is change the data type to date on fields with date then modify date display format.
With data in A1, in B1 enter:
=DATE(RIGHT(A1,4),MID(A1,4,2),LEFT(A1,2))
and apply the correct format to B1
You have to set the cell format to Custom Format using TT/MM/JJJJ

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.

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