ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Comparing Date Fields (https://www.excelbanter.com/excel-worksheet-functions/5797-comparing-date-fields.html)

Cathy

Comparing Date Fields
 
I have two date fields that are linked into one master spreadsheet from two
different sources. Once in the master spreadsheet they need to be compared.
When looking at the sources, they appear to both be true dates with a date
format. But when I try to compare them, they do not match. I have tried to
concantenate each with another field (a corresponding hour). When I perform
the concantenation I find that the two dates behave differently. One stays
in mm/dd/yyyy format, and the other becomes the Excel representation of a
date (ie 37989 = 1/3/2004). So then I added 'TEXT' logic to the dates. They
still will not compare properly. What else can I try?

Dave Peterson

Those concatenated cells that didn't change to a number is a clue that the value
in the original cell isn't really a data--it's just text masquerading as a
date. (Dates are just numbers to excel--formatted nicely for human's.)

You should be able to convert your text dates to real dates by selecting your
range (one column at at time) and then data|text to columns.

Choose fixed width and remove any lines that excel guessed.
make sure you choose the correct date style (mdy?)

then plop it right over the original range.

Then compare your cells once more.

And if you want to concatenate cells and include that formatting, you can use:

=a1&text(b1,"mm/dd/yyyy")

or if a1 contained a date and b1 a time:

=text(a1+b1,"mm/dd/yyyy hh:mm:ss")

But this formatting is just for you.

comparing two dates (even formatted differently) will match if the underlying
values match.

Cathy wrote:

I have two date fields that are linked into one master spreadsheet from two
different sources. Once in the master spreadsheet they need to be compared.
When looking at the sources, they appear to both be true dates with a date
format. But when I try to compare them, they do not match. I have tried to
concantenate each with another field (a corresponding hour). When I perform
the concantenation I find that the two dates behave differently. One stays
in mm/dd/yyyy format, and the other becomes the Excel representation of a
date (ie 37989 = 1/3/2004). So then I added 'TEXT' logic to the dates. They
still will not compare properly. What else can I try?


--

Dave Peterson



All times are GMT +1. The time now is 06:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com